Skip to content

Instantly share code, notes, and snippets.

@dj1020
Forked from jyurek/tm.sh
Created July 14, 2021 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dj1020/73fb21e652ce0d45ee444086a49c5413 to your computer and use it in GitHub Desktop.
Save dj1020/73fb21e652ce0d45ee444086a49c5413 to your computer and use it in GitHub Desktop.
Create and switch sessions in tmux quickly
#!/bin/sh
tm() {
if [ -z $1 ]; then
tmux switch-client -l
else
if [ -z "$TMUX" ]; then
tmux new-session -As $1
else
if ! tmux has-session -t $1 2>/dev/null; then
TMUX= tmux new-session -ds $1
fi
tmux switch-client -t $1
fi
fi
}
tm $1
# tmux session tab complete function
_tmux_complete_session() {
local IFS=$'\n'
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(tmux -q list-sessions | cut -f 1 -d ':')" -- "${cur}") )
}
complete -F _tmux_complete_session tm
# Toggle between the last two sessions
bind m switch-client -l
bind M command-prompt -p 'switch session:' "run \"tm '%%'\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment