Skip to content

Instantly share code, notes, and snippets.

@pagpires
Created June 16, 2023 07:53
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 pagpires/06c1cddd83988aff8ecc7aaa524a1be9 to your computer and use it in GitHub Desktop.
Save pagpires/06c1cddd83988aff8ecc7aaa524a1be9 to your computer and use it in GitHub Desktop.
tat
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment