23

I'd like a keyboard shortcut to work as so:

> e foo.txt

to expand as

> emacs foo.txt &

It's simple to use alias e=emacs, but how do I insert the & after the filename? I realize it may not be possible using just alias, so I'll accept any bash solution. If a shell script is needed please explain how it works.

  • 4
    You should use emacsclient or gnuclient to open a file from command-line instead of opening a new emacs for each file: emacswiki.org/emacs/EmacsClient – andcoz Sep 23 '11 at 15:46
36

Alias in bash can't have arguments, but you can use functions.

e() { emacs "$@" & }

then

e foo.txt

will do what you want.

  • 1
    This has a problem when I type e foo* in a directory with both foo.cpp and foo.h, only one of the files will open. – Hooked Sep 23 '11 at 18:50
  • 4
    @Hooked, then use "$@" instead of "$1" in the function. – AProgrammer Sep 23 '11 at 18:54
  • 1
    @AProgrammer that doesn't seem to work for wildcards. The syntax I'm using is: emacs $* & and an even better solution seems to be e() { command emacs $* & disown } – name Nov 19 '14 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.