29

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.

1
  • 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, 2011 at 15:46

1 Answer 1

43

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

e() { emacs "$@" & }

then

e foo.txt

will do what you want.

3
  • 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, 2011 at 18:50
  • 4
    @Hooked, then use "$@" instead of "$1" in the function. Sep 23, 2011 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, 2014 at 18:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .