Skip to content

Instantly share code, notes, and snippets.

@nnutter
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save nnutter/57d4fe31bfb120b31cc6 to your computer and use it in GitHub Desktop.

Select an option

Save nnutter/57d4fe31bfb120b31cc6 to your computer and use it in GitHub Desktop.
_tm_complete() {
COMPREPLY=()
local SESSIONS=$(tmux list-sessions | cut -f 1 -d :)
if [ ${#COMP_WORDS[@]} -eq 2 ]; then
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(compgen -W "$SESSIONS" -- $cur))
fi
}
complete -F _tm_complete tm
function tm {
session_name=$1
if [ -z "$session_name" ]; then
echo "ERROR: Must provide session name as argument."
return 1
fi
if tmux has-session -t "$session_name"; then
command tmux attach -t $session_name
else
command tmux new -s $session_name
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment