Skip to content

Instantly share code, notes, and snippets.

@jfryman
Last active May 18, 2017 01:45
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 jfryman/33a8e871c345999585f1941c329ec747 to your computer and use it in GitHub Desktop.
Save jfryman/33a8e871c345999585f1941c329ec747 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# Checks the condition in which emacs is called,
# and makes a determination as to how to spawn
# the emacsclient
#
# Depends on
if [ "$DEBUG" = "1" ]; then
set -x
fi
if xhost >& /dev/null;
# If not in x-session
if [ $? -ne 0 ]; then
EMACS_ENV_ARGS="-t"
else # in x-session
EMACS_ENV_ARGS="-c"
fi
# If in an editor session
PARENT_COMMAND=$(ps $PPID | tail -n 1 | awk "{print \$5}")
if [ "$PARENT_COMMAND" = "git" ]; then
EMACS_EDITOR_ARGS='-a ""'
elif [ "$PARENT_COMMAND" = "mutt" ]; then
EMACS_EDITOR_ARGS='-a ""'
elif [ "$EMACS_ENV_ARGS" = "-c" ]; then
EMACS_EDITOR_ARGS="-n"
fi
ps ax | grep -v grep | grep "emacs --daemon" > /dev/null 2>&1
if [ $? -eq 1 ]; then
/usr/bin/emacs --daemon
fi
emacsclient $EMACS_ENV_ARGS $EMACS_EDITOR_ARGS $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment