Topic: https://brettterpstra.com/2013/03/30/a-multi-purpose-editor-variable/
hide preview

What's next? verify your email address for reply notifications!

Evan Teitelman 11y, 297d ago

I wrote something that can handle directory changing and sudoedit: https://github.com/EvanTeit...

I'm working on a version that can handle a number of filetypes: https://github.com/EvanTeit...

hide preview

What's next? verify your email address for reply notifications!

vrtcl1dvoshun 11y, 353d ago

If you use zsh, this is easily done with an alias:

% alias -s sh=vim

which would set any file with the extension *.sh to be opened with the command vim (according to your $PATH). Thus I can now type:

% foo.sh

which essentially runs the following command:

% vim foo.sh

and opens my file!

hide preview

What's next? verify your email address for reply notifications!

Stuart Axon 11y, 354d ago

I think xdg-open is what you want to open using the freedesktop associated file.

hide preview

What's next? verify your email address for reply notifications!

Zash 11y, 354d ago

You might want to replace $1 with "$@", then it'll work with any number of files

hide preview

What's next? verify your email address for reply notifications!

Foo 11y, 354d ago

You may want to enclose $1 in quotation marks or you'll run into trouble with file names containing spaces.

hide preview

What's next? verify your email address for reply notifications!

Benyamin Sussman 11y, 354d ago

OMG. Do you realise that you have created a gigantic security hole in your system by doing this? If I was the auditor of your system you would be marked down severely for this.

remark link
hide preview

What's next? verify your email address for reply notifications!

nathan_f77 11y, 354d ago

How so? How is this more dangerous than setting EDITOR="/usr/local/bin/vim"

hide preview

What's next? verify your email address for reply notifications!

Kata 11y, 354d ago

Why is this a security hole (aside from the issue regarding $1 not being quoted)?

hide preview

What's next? verify your email address for reply notifications!

Steven Fisher 11y, 354d ago

Your solution is more flexible (and I'm going to adopt it for some things), but it's worth mentioning that many of these tools use EDITOR as a fallback. svn has SVN_EDITOR, git has GIT_EDITOR, etc.

remark link
hide preview

What's next? verify your email address for reply notifications!

ttscoff 11y, 354d ago

Yep, I'm aware. The overall flexibility of just managing all of it in one script is just preferable to me.

hide preview

What's next? verify your email address for reply notifications!

anonymous coward 11y, 355d ago

After going through some other blog entries, I see you have a nice little history of offering badly designed "solutions". If you keep your bad hacks to yourself I won't say a damn thing but once you start displaying them for others as "solutions", don't get defensive when other criticize them.

hide preview

What's next? verify your email address for reply notifications!

anonymous coward 11y, 355d ago

Why use bash? It uses no bash specific functionality and not everyone has (or wants) bash on their system.

hide preview

What's next? verify your email address for reply notifications!

Bernd 11y, 355d ago

This script can be simplified:

You can use the following code to do so:

*_EDITMSG|*MERGE_MSG|*_TAGMSG)
/usr/local/bin/vim $1 ;;

remark link
hide preview

What's next? verify your email address for reply notifications!

Brett Terpstra 11y, 354d ago

Updated the gist for this, thanks. I kept them all separate to make it easy to edit which editor per file type, but it only makes sense to combine all the git messages together.

hide preview

What's next? verify your email address for reply notifications!

Erica Windisch 11y, 355d ago

Unless you intend to use ed or ex, set the VISUAL variable, not EDITOR!

remark link
hide preview

What's next? verify your email address for reply notifications!

Brett Terpstra 11y, 355d ago

for git (and all other purposes I've found) $EDITOR works interchangeably. What's the difference and under what circumstances?

remark link parent
hide preview

What's next? verify your email address for reply notifications!

z 11y, 354d ago
hide preview

What's next? verify your email address for reply notifications!