41 lines
1.6 KiB
Bash
Executable File
41 lines
1.6 KiB
Bash
Executable File
#!/bin/zsh
|
|
|
|
switch_to() {
|
|
[[ -z $TMUX ]] && tmux attach-session -t $1 || tmux switch-client -t $1
|
|
}
|
|
|
|
hydrate() {
|
|
local tmux_hydrate_files_dir="$XDG_CONFIG_HOME/tmux/session-hydrate-files"
|
|
local tmux_hydrate_path="$tmux_hydrate_files_dir/.tmux-session-hydrate-default"
|
|
[[ $1 = "thinking" ]] && tmux_hydrate_path="$tmux_hydrate_files_dir/.tmux-session-hydrate-thinking"
|
|
[[ $1 = "listening" ]] && tmux_hydrate_path="$tmux_hydrate_files_dir/.tmux-session-hydrate-listening"
|
|
[[ -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=$([[ -n $(pgrep tmux) ]] && tmux list-sessions || echo '')
|
|
local search_dirs=(
|
|
$DIR_HOME_BOX
|
|
$DIR_DEV
|
|
$DIR_GIT_PROJECTS/*
|
|
)
|
|
local target_name=''
|
|
local target_path=''
|
|
|
|
[[ $# -eq 1 ]] && target_path=$1 ||
|
|
target_path=$(find $search_dirs -mindepth 1 -maxdepth 1 -type d | fzf)
|
|
|
|
if [[ $target_path = "." ]]; then target_name=$(basename $(pwd)) && target_path=$(pwd);
|
|
elif [[ $target_path = "hub" ]]; then target_name="hub" && target_path="$HOME";
|
|
elif [[ $target_path = "thinking" ]]; then target_name="thinking" && target_path="$DIR_SCRATCH_NOTES";
|
|
elif [[ $target_path = "listening" ]]; then target_name="listening" && target_path="$DIR_MUSIC";
|
|
elif [[ -n $target_path ]]; then target_name=$(basename "$target_path" | tr . _);
|
|
fi
|
|
|
|
[[ -z $target_name ]] && exit 0
|
|
|
|
! (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
|