Skip to content

Instantly share code, notes, and snippets.

@silvercircle
Created April 10, 2018 06:00
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 silvercircle/feaead2ce149d133b63bb2c9e35e2bd1 to your computer and use it in GitHub Desktop.
Save silvercircle/feaead2ce149d133b63bb2c9e35e2bd1 to your computer and use it in GitHub Desktop.
Start emacsclient and only create a new frame if none exists. Otherwise reuse frame. Pass -nw to force console-emacs
#!/bin/bash -e
if [[ "$DISPLAY" ]]; then
frame=`emacsclient -a '' -e "(member \"$DISPLAY\" (mapcar 'terminal-name (frames-on-display-list)))" 2>/dev/null`
[[ "$frame" == "nil" ]] && opts='-c' # if there is no frame open create one
[[ "${@/#-nw/}" == "$@" ]] && opts="$opts -n" # don't wait unless we've asked to run in a terminal
else
opts='-nw'
fi
exec emacsclient -a '' $opts "$@"
Source and copyright: https://emacs.stackexchange.com/questions/12894/make-emacsclient-create-a-frame-only-if-there-isnt-one-already
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment