Skip to content

Instantly share code, notes, and snippets.

@cybic
Last active January 26, 2017 18:25
Show Gist options
  • Save cybic/6375457 to your computer and use it in GitHub Desktop.
Save cybic/6375457 to your computer and use it in GitHub Desktop.
Get tab-completion for the `tmux' command in bash.
# bash completion for tmux
# Written by Oystein Steimler <[email protected]>
#
# $ sudo cp tmux-completion.bash /etc/bash_completion.d/tmux
# $ . /etc/bash_completion.d/tmux
#
_sessions() {
SESSIONS=`tmux ls -F#{session_name} | xargs echo`
}
_tmux() {
local cur prev comp
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case "$prev" in
attach)
comp="-t"
;;
att)
comp="-t"
;;
new)
comp="-s"
;;
-t)
_sessions
comp="$SESSIONS"
;;
tmux)
comp="attach new ls list"
;;
esac
COMPREPLY=( $(compgen -W "${comp}" -- ${cur}) )
return 0
}
complete -F _tmux tmux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment