function emacs(){
is_running=$(ps aux | grep Emacs.app | wc -l)
if [ $# -eq 0 ]; then
if [ $is_running -gt 1 ]; then
osascript -e '
tell application "Emacs"
activate
end tell
'
else
cmd="/Applications/Emacs.app/Contents/MacOS/Emacs &"
eval $cmd;
fi
else
if [ $is_running -gt 1 ]; then
cmd="emacsclient "$@" &";
eval $cmd;
else
cmd="/Applications/Emacs.app/Contents/MacOS/Emacs "$@" &";
eval $cmd;
fi
fi
}
.emacs
(load "server")
(unless (server-running-p) (server-start))
(global-set-key (kbd "C-x C-c") 'server-edit)
(defalias 'exit 'save-buffers-kill-emacs)