-
-
Save dj1020/73fb21e652ce0d45ee444086a49c5413 to your computer and use it in GitHub Desktop.
Create and switch sessions in tmux quickly
This file contains 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
#!/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 |
This file contains 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
# 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 |
This file contains 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
# 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