Skip to content

Instantly share code, notes, and snippets.

@alchem0x2A
Last active August 18, 2019 16:19
Show Gist options
  • Save alchem0x2A/f5197a58ff791a428ab0d5595f26b035 to your computer and use it in GitHub Desktop.
Save alchem0x2A/f5197a58ff791a428ab0d5595f26b035 to your computer and use it in GitHub Desktop.
[Emacs] Wrapping up emacsclient to automatically start server
#!/bin/sh
# Provide a wrapper of emacsclient that automatically opens up Emacs or server
function ec_wrapper {
GREEN='\033[0;32m'
NC='\033[0m'
buffers=$@
cmd="emacsclient -nqc"
# Excecute command
$cmd $buffers &> /dev/null
return_code=$?
if (( $return_code != 0))
then
pid=$(pgrep -ai "emacs")
# If emacs current running?
if (( ${#pid} == 0 )) # No pid returned
then # No emacs running, then open the GUI
emacs --chdir $(pwd) $@ & &> /dev/null
suc=$?
return $suc
else
echo "There is a running Emacs instance but I can't find find the server."
echo -e "Run ${GREEN}M-x server-start${NC} in Emacs to enable it."
fi
else
return 0 # Success
fi
}
alias ec=ec_wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment