dotfiles/bin/t

32 lines
767 B
Plaintext
Raw Normal View History

2022-10-03 16:46:49 +00:00
#!/usr/bin/env bash
if [[ $# -eq 1 ]]; then
selected=$1
else
2023-12-08 07:18:00 +00:00
selected=$(zoxide query -l | grep -v /tmp | grep -v "^${HOME}/\." | grep -v "^${HOME}/Code$" | grep -v "/main$" | fzf --reverse)
fi
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
if [[ -z $TMUX ]]; then
tmux attach-session -t $selected_name
else
tmux switch-client -t $selected_name
fi