scatterd-dotfiles/bin/tat
Roman Frołow 2e49faecfe has-session - only exact matches
from man
>If the session name is prefixed with an ‘=’, only an exact match is accepted (so ‘=mysess’ will only match exactly ‘mysess’, not ‘mysession’).
2019-08-20 14:37:10 -04:00

31 lines
580 B
Bash
Executable file

#!/bin/sh
#
# Attach or create tmux session named the same as current directory.
path_name="$(basename "$PWD" | tr . -)"
session_name=${1-$path_name}
not_in_tmux() {
[ -z "$TMUX" ]
}
session_exists() {
tmux has-session -t "=$session_name"
}
create_detached_session() {
(TMUX='' tmux new-session -Ad -s "$session_name")
}
create_if_needed_and_attach() {
if not_in_tmux; then
tmux new-session -As "$session_name"
else
if ! session_exists; then
create_detached_session
fi
tmux switch-client -t "$session_name"
fi
}
create_if_needed_and_attach