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

@@ -21,10 +21,12 @@ bind -r l select-pane -R
bind r source-file "~/.config/tmux/tmux.conf" \; display-message "tmux.conf reloaded" bind r source-file "~/.config/tmux/tmux.conf" \; display-message "tmux.conf reloaded"
# kill the current session # kill the current session
bind Q rename-session zzzz-temp-kill\; switch-client -p\; kill-session -t zzzz-temp-kill bind-key Q rename-session zzzz-temp-kill\; switch-client -p\; kill-session -t zzzz-temp-kill
# use tmux-sessionizer in place of f find # custom find using tmux-sessionizer
bind-key -r f run-shell "tmux neww ~/.local/bin/tmux-sessionizer" unbind-key f
bind-key f run-shell "tmux neww ~/.local/bin/tmux-sessionizer existing"
bind-key F run-shell "tmux neww ~/.local/bin/tmux-sessionizer"
# bind -r D neww -c "#{pane_current_path}" "[[ -e TODO.md ]] && $EDITOR TODO.md || $EDITOR ~/personal/dev/todo.md" # bind -r D neww -c "#{pane_current_path}" "[[ -e TODO.md ]] && $EDITOR TODO.md || $EDITOR ~/personal/dev/todo.md"

View File

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