Skip to content

Instantly share code, notes, and snippets.

@bdowling
Last active April 5, 2017 17:03
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 bdowling/d0a4759e9f597751981e5948124a5acb to your computer and use it in GitHub Desktop.
Save bdowling/d0a4759e9f597751981e5948124a5acb to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Script to start or restart a left and right tmux session
# Can be called multiple times and does the right thing(tm)
#
# Makes use of swind and xdotool to arrange windows on screen
# https://gist.github.com/bdowling/ad87c58362af7c28806bb2292436222d
#
# by Brian Dowling
#
# Can ignore stderr and not test because it complains but won't duplicate sessions
tmux -2 new-session -d -s left 2>/dev/null
tmux -2 new-session -d -s right 2>/dev/null && tmux clock-mode
geoleft=120x44+30+434
georight=120x44+1255+434
xdotool search --name left: --class urxvt --all > /dev/null ||
urxvt -geometry $geoleft -name 'left: tmux' -e sh -c "tmux -2 attach -t left" &
xdotool search --name right: --class urxvt --all > /dev/null ||
urxvt -geometry $georight -name 'right: tmux' -e sh -c "tmux -2 attach -t right" &
if [ $(ssh-add -l | fgrep -v 'agent has no identities' | wc -l) -le 0 ]; then
if ! pidof ssh-add >/dev/null 2>&1 ; then
tmux split-window -t left:0 "ssh-add"
fi
fi
# Background task to wait for the windows and then move them based on physical display rather than mucking
# with font size and rows/columns, bit of flicker on start, but it works.
( while !(xdotool search -name left: && xdotool search -name right:) >/dev/null 2>&1; do usleep 5000; done
swind left -name left:; swind right -name right: ) &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment