Skip to content

Instantly share code, notes, and snippets.

@qleguennec
Created December 6, 2015 14:45
Show Gist options
  • Save qleguennec/c13e4db09358ee415ecc to your computer and use it in GitHub Desktop.
Save qleguennec/c13e4db09358ee415ecc to your computer and use it in GitHub Desktop.
#! /bin/sh
function layout()
{
tmux lsw | head -n 1 | egrep -o -e "\[layout.*$" | awk '{print $2}' | sed 's/.$//'
}
function curwindow()
{
tmux lsw | awk '{print $2}' | grep '*' | sed 's/.$//'
}
function cursession()
{
tmux ls | grep attached | cut -d: -f1
}
function conf()
{
echo "$HOME/.tmuxinator/$(cursession).yml"
}
case $1 in
only)
if [[ -n "$2" ]]; then
tmux switch-client -t "$2"
tmux ls | cut -d: -f1 | grep -v "$2" | xargs -I{} tmux kill-session -t {}
else
tmux ls | grep -v attached | cut -d: -f1 | xargs -I{} tmux kill-session -t {}
fi
;;
reload)
OLD=$(tmux ls | grep attached | cut -d: -f1)
tmux new-session -d -s buffer "mux start $OLD"
tmux switch-client -t buffer
tmux kill-session -t "$OLD"
;;
layout)
layout
;;
save-layout)
LINE=$(grep -n -A1 "$(curwindow)" "$(conf)" | tail -n 1 | cut -d- -f1)
sed -i $LINE's/layout:.*/layout: '$(layout)'/' $(conf)
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment