Skip to content

Instantly share code, notes, and snippets.

@tiziano88
Last active December 14, 2015 23:29
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiziano88/5166177 to your computer and use it in GitHub Desktop.
Save tiziano88/5166177 to your computer and use it in GitHub Desktop.
Sane tmux session management for zsh with dynamic session name autocompletion.
function mux {
case "$1" in
"")
# If no args, list all the available "visible" sessions.
tmux ls | grep --color=never -C0 "^[^.]"
;;
*)
# "Hidden" sessions have a name starting with a '.'.
session_id=".$1.`date +%Y%m%d%H%M%S`"
# Try to create a hidden session and attach it to the specified one, killing it once finished.
# Failing this, create a new "visible" session with the specified name, and keep it alive.
(tmux new-session -s "$session_id" -t "$1"; tmux kill-session -t "$session_id") || tmux new-session -s "$1"
;;
esac
}
# Dynamic autocompletion for "visible" session names.
function _mux {
reply=(`mux | cut -d: -f1`)
}
compctl -K _mux mux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment