I find running the following is different from just running emacs
on mac
/Applications/Emacs.app/Contents/MacOS/Emacs -nw
Should I create an alias in zsh/bash for it?
Just to expand on @ghoetker's answer:
~/.zshrc
in your favorite text editor.alias emacs='$(/Applications/Emacs.app/Contents/MacOS/Emacs "$@")'
source ~/.zshrc
From now on, typing emacs
will open up Emacs in the Finder.
Edit: to cover some questions that have come up, the link in this answer is only one source for Emacs, and there are dozens of others. Anywhere you download it from you will need to take the proper precautions to make sure it's being downloaded from a safe source. How exactly to do that is beyond the scope of this question but if anyone has a particular problem please post it and I'll do what I can to help.
mvim
), it opens in a new window and the shell returns immediately.
Yes. An alias to the binary within Emacs.app is useful and will allow to call an up-to-date version of emacs from the terminal via “emacs”. I have the following set up
alias emacs='$(/Applications/Emacs.app/Contents/MacOS/Emacs "$@")'
Applying Dave Kanter's recipe, I still run into trouble: "Emacs" can't be opened because Apple cannot check it for malicious software.
To get it to run, I had to open Settings, Settings, Security & Privacy, General tab and there give Emacs permission to open anyway, at my own risk.
Now I can run Emacs from the command line, albeit without options or arguments (no file name, no -nw
option...).
"Emacs" can't be opened because Apple cannot check it for malicious software
, see also this answer: emacs.stackexchange.com/a/69444/25843
Commented
Nov 23, 2021 at 19:23
I initially used:
alias emacs='$(/Applications/Emacs.app/Contents/MacOS/Emacs "$@")'
allowing me to open Emacs from terminal but not in it even if I used emacs -nw
After finding I couldn't open Emacs to run in terminal, I replaced the original alias in my .zshrc with:
alias emacs='$(/Applications/Emacs.app/Contents/MacOS/Emacs -nw)'
Now, if I want the gui version I open Emacs using spotlight. If I want the terminal version, I type "emacs" in terminal providing the best of both worlds. With the original line using "$@" I couldn't get Emacs to run in terminal even using "emacs -nw"
Assuming you've downloaded the Mac app to your Applications folder (you can get it from https://emacsformacosx.com/) you can just alias the binary in the app bundle.
In your .zshrc
:
alias emacs='/Applications/Emacs.app/Contents/MacOS/Emacs -nw'
The -nw
/--no-window-system
option tells emacs not to use the window system, i.e. run in terminal mode which is what I prefer.
If you prefer to use the GUI interface, you'll probably want to run emacs in the background. Appending &
to the end of your command tells your shell to run the command in the background.
In your .zshrc:
alias emacs='/Applications/Emacs.app/Contents/MacOS/Emacs'
In the terminal:
emacs my-file.txt &
Aside:
Modern OS X installations seem to come with mg
(comes from "Micro Gnu emacs") which is a tiny binary with that familiar emacs interface. If you're just doing barebones text file editing, you don't even need to get an emacs binary. You can either use mg
directly, or if your muscle memory is too strong:
alias emacs=mg
(I'm not sure what the extra stuff in Raydot's answer is trying to do, but AFAICT it prevents command line arguments from making it to emacs which makes it a not very useful alias for use on the command line)
/usr/bin/emacs
is too old. Feel free to create an alias for it.