2025-01-15 00:44:24 -06:00
|
|
|
#!/bin/zsh
|
|
|
|
|
|
|
|
switch_to() {
|
2025-01-18 14:14:54 -06:00
|
|
|
[[ -z $TMUX ]] && tmux attach-session -t $1 || tmux switch-client -t $1
|
2025-01-15 00:44:24 -06:00
|
|
|
}
|
|
|
|
|
2025-01-18 14:14:54 -06:00
|
|
|
tmux_session_exists() {
|
|
|
|
[[ -n $(pgrep tmux) ]] && tmux list-sessions | grep -q "^$1:"
|
2025-01-15 00:44:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
hydrate() {
|
2025-01-18 14:14:54 -06:00
|
|
|
local tmux_hydrate_path="$HOME/.local/bin/.tmux-session-hydrate"
|
|
|
|
[[ -f $2/.tmux-session-hydrate ]] && tmux_hydrate_path="$2/.tmux-session-hydrate"
|
|
|
|
[[ -f $tmux_hydrate_path ]] && tmux send-keys -t $1 "source $tmux_hydrate_path" c-M
|
2025-01-15 00:44:24 -06:00
|
|
|
}
|
|
|
|
|
2025-01-18 14:14:54 -06:00
|
|
|
local search_dirs=(
|
|
|
|
$HOME
|
|
|
|
$HOMEBOX
|
|
|
|
$DEVDIR
|
|
|
|
$DEVDIR/git
|
2025-01-20 16:59:10 -06:00
|
|
|
$DEVDIR/git/*
|
2025-01-18 14:14:54 -06:00
|
|
|
)
|
|
|
|
local selected_path=''
|
|
|
|
[[ $# -eq 1 ]] && selected_path=$1 ||
|
|
|
|
selected_path=$(find $search_dirs -mindepth 1 -maxdepth 1 -type d | fzf)
|
|
|
|
[[ -z $selected_path ]] && exit 0
|
|
|
|
|
|
|
|
local selected_name=$(basename "$selected_path" | tr . _)
|
|
|
|
|
|
|
|
! (tmux_session_exists $selected_name) &&
|
|
|
|
tmux new-session -d -s $selected_name -c $selected_path &&
|
|
|
|
hydrate $selected_name $selected_path
|
2025-01-15 00:44:24 -06:00
|
|
|
switch_to $selected_name
|