Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
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

1 Answer 1

up vote 16 down vote accepted

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

e() { emacs "$@" & }

then

e foo.txt

will do what you want.

share|improve this answer
    
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
1  
@Hooked, then use "$@" instead of "$1" in the function. –  AProgrammer Sep 23 '11 at 18:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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