Last active
May 18, 2017 01:45
-
-
Save jfryman/33a8e871c345999585f1941c329ec747 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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