Last active
December 14, 2015 23:29
-
-
Save tiziano88/5166177 to your computer and use it in GitHub Desktop.
Sane tmux session management for zsh with dynamic session name autocompletion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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