This commit is contained in:
2025-01-24 21:05:16 -06:00
parent 4c5da310d7
commit 1901d1fe80
2 changed files with 27 additions and 20 deletions

View File

@@ -4,35 +4,40 @@ switch_to() {
[[ -z $TMUX ]] && tmux attach-session -t $1 || tmux switch-client -t $1
}
tmux_session_exists() {
[[ -n $(pgrep tmux) ]] && tmux list-sessions | grep -q "^$1:"
tmux_session_names() {
return $(([[ -n $(pgrep tmux) ]] && $(tmux list-sessions) || ()))
}
#tmux_session_exists() {
# echo $2 | grep -q "^$1:"
#}
hydrate() {
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
}
local existing_sessions=$(tmux_session_names)
local search_dirs=(
$HOMEBOX
$DEVDIR
$DEVDIR/git/*
)
local selected_path=''
[[ $# -eq 1 ]] && selected_path=$1 ||
selected_path=$(
find $search_dirs -mindepth 1 -maxdepth 1 -type d |
(echo 'hub' && cat) |
fzf
)
[[ -z $selected_path ]] && exit 0
local target_name=''
local target_path=''
[[ $# -eq 1 ]] && target_path=$1 ||
target_path=$(find $search_dirs -mindepth 1 -maxdepth 1 -type d | fzf)
[[ $target_path = "existing" ]] && target_name=$(echo $existing_sessions | fzf) ||
[[ $target_path = "hub" ]] && target_name="hub" && target_path=$HOME ||
[[ -n $target_path ]] && target_name=$(basename "$target_path" | tr . _)
[[ -z $target_name ]] && exit 0
local selected_name=''
[[ "$selected_path" = "hub" ]] && selected_name="hub" && selected_path=$HOME ||
selected_name=$(basename "$selected_path" | tr . _)
echo 'zxcv'
echo $target_name
echo $target_path
! (tmux_session_exists $selected_name) &&
tmux new-session -d -s $selected_name -c $selected_path &&
hydrate $selected_name $selected_path
switch_to $selected_name
! (echo $existing_sessions | grep -q "^$target_name:") &&
tmux new-session -d -s $target_name -c $target_path &&
hydrate $target_name $target_path
switch_to $target_name