Skip to content

Instantly share code, notes, and snippets.

@vedang
Created August 7, 2011 11:28
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 vedang/1130303 to your computer and use it in GitHub Desktop.
Save vedang/1130303 to your computer and use it in GitHub Desktop.
Shell script to start a new instance of emacs or switch to an already running one.
#!/bin/bash
# get id of emacs
win=$(xdotool search --onlyvisible --class emacs | head -1)
if [ "x$win" = x ]; then
# Emacs is not running
# switch to viewport 1, which is my coding viewport
~/incoming-src/dotfiles/scripts/compiz-send.py vpswitch switch_to_1_key
gxmessage -center -timeout 2 -nofocus -buttons "" -borderless "loading emacs..."&
# start Emacs
exec /usr/local/bin/emacs &
else
# Emacs is already running...
if [ $win = $(xdotool getwindowfocus) ]; then
# ...and focused
# do nothing
sleep 0.2;
else
# switch to it
xdotool windowactivate $win
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment