-
-
Save eventualbuddha/11294965 to your computer and use it in GitHub Desktop.
tmux session management
This file contains hidden or 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 helper | |
_t_usage() { | |
echo "t SESSION # attach to SESSION or do \`z SESSION\` and create tmux SESSION" | |
} | |
t() { | |
case "$1" in | |
"-h" | "--help") | |
_t_usage | |
return 0 | |
;; | |
"" | "-l" | "--list") | |
tmux list-sessions | |
return 0 | |
;; | |
-*) | |
_t_usage | |
return 1 | |
;; | |
*) | |
session=$(echo $1 | sed 's/\./-/g') | |
jumpdir=$1 | |
;; | |
esac | |
for s in $(tmux list-sessions -F '#S' 2>/dev/null); do | |
if [[ "$s" = "$session" ]]; then | |
tmux attach-session -t "$session" | |
return $? | |
fi | |
done | |
z $jumpdir || true | |
tmux new-session -s "$session" | |
return $? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment