Finish initial setup of tmux-sessionizer

This commit is contained in:
2025-01-18 14:14:54 -06:00
parent cb8f07a711
commit 201cd90ee8
10 changed files with 67 additions and 66 deletions

View File

@ -0,0 +1,14 @@
#!/bin/zsh
local omitted_dirs=(
$HOME
$HOMEBOX
$DEVDIR
)
[[ ! ${omitted_dirs[(re)$(pwd)]} ]] &&
tmux new-window -d -n cmd &&
tmux rename-window $EDITOR &&
$EDITOR .
clear

View File

@ -1,10 +0,0 @@
#!/bin/zsh
if [[ "$(pwd)" == $HOME || "$(pwd)" == $HOMEBOX ]]; then
clear
return
fi
tmux new-window -dn scratch
vim .
clear

59
src_files/.local/bin/tmux-sessionizer Normal file → Executable file
View File

@ -1,49 +1,36 @@
#!/bin/zsh
switch_to() {
if [[ -z $TMUX ]]; then
tmux attach-session -t $1
else
tmux switch-client -t $1
fi
[[ -z $TMUX ]] && tmux attach-session -t $1 || tmux switch-client -t $1
}
has_session() {
tmux list-sessions | grep -q "^$1:"
tmux_session_exists() {
[[ -n $(pgrep tmux) ]] && 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
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
}
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
local search_dirs=(
$HOME
$HOMEBOX
$DEVDIR
$DEVDIR/git
$DEVDIR/git/me
$DEVDIR/git/gary
$DEVDIR/git/other
)
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
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
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
switch_to $selected_name