Skip to content

Instantly share code, notes, and snippets.

@r-medina
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r-medina/0d29407b20de545d1cf8 to your computer and use it in GitHub Desktop.
Save r-medina/0d29407b20de545d1cf8 to your computer and use it in GitHub Desktop.
emacs stuff in .bashrc
# checks if there is an emacs daemon running: yes - open a client with the file, no -
# start a daemon, open client
#
# did this because i only use emacs in terminal and dont want
# emacsclient <file_name> to open file in an open frame
#
# caution: even though all arguments passed via `${@:1}`, `emacsclient` only opens
# one file, unlike `emacs`
#
# excluding `grep` from `ps`:
# http://superuser.com/questions/409655/excluding-grep-from-process-list
# mass arguments:
# http://wiki.bash-hackers.org/scripting/posparams#mass_usage
function emacssmart {
# `ps -e` - print all processes
# `grep '[e]macs --daemon'` - greps out matching processes except itself
if [[ $(ps -e | grep '[e]macs --daemon') ]]
then
# if daemon is running
emacsclient -nw -c ${@:1} # windowless client, new one, pass all args (but
# only one file will open)
else # no daemon
pushd .
cd $HOME # just makes everything better
\emacs --daemon
popd
# start daemon, recursively call self. fuck performance
emacssmart ${@:1}
fi
}
# launches emacs on login
if [[ ! $(ps -e | grep '[e]macs --daemon') ]]
then
\emacs --daemon 1>.emacs.d/init.log 2>&1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment