fix: Make tmux-sessioniser work outside of tmux

This commit is contained in:
Oliver Davies 2021-09-17 22:35:47 +01:00
parent 92d1ddeff2
commit d39bfee514

View file

@ -14,16 +14,26 @@ else
selected=$(find ~/ ~/Code ~/Code/clients ~/Code/os ~/Code/Personal ~/Documents/Talks/ -mindepth 1 -maxdepth 1 -type d -not -name ".*" | sort | fzf)
fi
selected_name=$(basename "$selected" | tr . -)
if [[ -z $selected ]]; then
exit 0
fi
is_tmux_running=$(pgrep tmux)
selected_name=$(basename "$selected" | tr . -)
if [[ -z $TMUX ]] && [[ -z $is_tmux_running ]]; then
tmux new-session -s $selected_name -c $selected
exit 0
fi
# Create a new session if tmux does not already have a session matching the
# selected session name.
if ! tmux has-session -t $selected_name 2> /dev/null; then
tmux new-session -s $selected_name -c $selected -d
fi
tmux switch-client -t $selected_name
if [[ -z $TMUX ]]; then
tmux attach-session -t $selected_name
else
tmux switch-client -t $selected_name
fi