-
-
Save akkerman/6a3e5b75398a6152b1478c2880409fa2 to your computer and use it in GitHub Desktop.
start a tmux session in the current directory
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
#!/usr/bin/env bash | |
# start a tmux session in the current directory | |
dirname="$(basename $PWD)" | |
# tmux sessionname cannot contain a dot, replace with underscore | |
session="${dirname/./_}" | |
tmux_sessions=$(tmux ls -F '#{session_name}') | |
if [ -n "$TMUX" ]; then | |
# already in tmux | |
if [[ $tmux_sessions != *"$session"* ]]; then | |
# force create session, don't attach | |
TMUX='' tmux new-session -Ad -s "$session" | |
fi | |
tmux switch-client -t "$session" | |
else | |
# not in tmux | |
# create session, or attach when exists | |
tmux new-session -As "$session" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment