44 lines
1.2 KiB
Bash
Executable File
44 lines
1.2 KiB
Bash
Executable File
#!/bin/zsh
|
|
|
|
switch_to() {
|
|
[[ -z $TMUX ]] && tmux attach-session -t $1 || tmux switch-client -t $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 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
|
|
|
|
echo 'zxcv'
|
|
echo $target_name
|
|
echo $target_path
|
|
|
|
! (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
|