ht-ica
Last Updated: February 25, 2016
·
2.217K
· oleiade
Img 1416

Tmux : Named sessions with autocomplete

Tmux is a great tool, but I usually find it hard to track my sessions. So after a few googling I found a trick, which allows to name, and easily retrieve alive tmux sessions (with autocomplete)

Here's the function (zsh)

function tm() {
    [[ -z "$1" ]] && { echo "usage: tm <session>" >&2; return 1; }
    tmux has -t $1 && tmux attach -t $1 || tmux new -s $1
}

function __tmux-sessions() {
    local expl
    local -a sessions
    sessions=( ${${(f)"$(command tmux list-sessions)"}/:[ $'\t']##/:} )
    _describe -t sessions 'sessions' sessions "$@"
}
compdef __tmux-sessions tm

Example :

$ tm testsession1  # Launch a tmux session named testsession1
$ tm testsession2  # Launch a second tmux session named testsession2
$ tm <tab>  # List (autocomplete) existing sessions

Source

Say Thanks
Respond
Filed Under

Awesome Job

A3e45f3a cade 11e7 83bc 71c9546a2749
Systems Engineer
·
Fulton, Maryland or Remote
·
Full Time