Move copy targets into directory; add tmux sessionizer

This commit is contained in:
david
2025-04-04 16:55:39 -05:00
parent bfc8c03bbe
commit f777f7632b
10 changed files with 81 additions and 13 deletions

View File

@ -0,0 +1,49 @@
#!/bin/zsh
switch_to() {
if [[ -z $TMUX ]]; then
tmux attach-session -t $1
else
tmux switch-client -t $1
fi
}
has_session() {
tmux list-sessions | grep -q "^$1:"
}
hydrate() {
if [ -f $2/.tmux-sessionizer ]; then
tmux send-keys -t $1 "source $2/.tmux-session-setup" c-M
elif [ -f $HOME/.tmux-sessionizer ]; then
tmux send-keys -t $1 "source $HOME/.tmux-session-setup" c-M
fi
}
if [[ $# -eq 1 ]]; then
selected=$1
else
# If someone wants to make this extensible, i'll accept
# PR
selected=$(find ~/ ~/personal ~/personal/dev/env/.config -mindepth 1 -maxdepth 1 -type d | fzf)
fi
if [[ -z $selected ]]; then
exit 0
fi
selected_name=$(basename "$selected" | tr . _)
tmux_running=$(pgrep tmux)
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
tmux new-session -s $selected_name -c $selected
hydrate $selected_name $selected
exit 0
fi
if ! has_session $selected_name; then
tmux new-session -ds $selected_name -c $selected
hydrate $selected_name $selected
fi
switch_to $selected_name