Search code examples
bashcommand-linemacos-sierra

How to always append an ampersand for certain commands? (MacOS / bash)


Whenever I open emacs, I always want to run it in the background. How can I make it so that whenever I type "emacs xyz" the shell automatically runs "emacs xyz &"?


Solution

  • The following shell function (which can be put in .bashrc) does what you're asking for:

    emacs() { command emacs "$@" & }
    

    command ensures that the real (external) emacs command is invoked, rather than having the function call itself recursively. "$@" expands to the list of arguments, ensuring that they're passed through.