dotfiles/.bin/tmux-projectinator

45 lines
1.1 KiB
Plaintext
Raw Normal View History

2023-11-11 13:13:02 +00:00
#!/bin/sh
# Quit on escape
set -o emacs
bind '"\e": "\C-W\c-d"'
move_pane () {
tmux has-session -t $SESSION_NAME 2>/dev/null
if [ $? != 0 ]; then
tmux new-session -s $SESSION_NAME -d -n $PROJECT -c $1
fi
tmux has-session -t $SESSION_NAME:$PROJECT 2>/dev/null
if [ $? != 0 ]; then
tmux new-window -t $SESSION_NAME: -n $PROJECT -d -c $1
fi
tmux switch-client -t $SESSION_NAME:$PROJECT
# Close tmux popup if any
tmux display-popup -C
}
2023-11-11 13:13:02 +00:00
declare -A CUSTOM_SESSIONS
CUSTOM_SESSIONS[Projects]=Halia
SELECTED=$(find . -name .git -type d -prune -not -path "./.*" 2>/dev/null | sed 's/\/.git//' | cut -d'/' -f2- | fzf)
ROOT=$(echo $SELECTED | cut -d '/' -f1)
PROJECT=$(echo $SELECTED | rev | cut -d '/' -f1 | rev)
SESSION_NAME=$([ -z "${CUSTOM_SESSIONS[$ROOT]}" ] && echo "$ROOT" || echo "${CUSTOM_SESSIONS[$ROOT]}")
while getopts ":l" option; do
case $option in
l)
tmux send-keys "cd $SELECTED" Enter
2023-11-11 13:13:02 +00:00
# Close tmux popup if any
tmux display-popup -C
;;
esac
done
2023-11-11 13:13:02 +00:00
if [ $OPTIND -eq 1 ]; then move_pane "$SELECTED"; fi