Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2018 06:00
What would you like to do?
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
exec emacsclient -a '' $opts "$@"
Source and copyright:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment