feat(tmux): Add local project opener shortcut

This commit is contained in:
Tanguy Herbron 2023-11-13 00:14:45 +01:00
parent 62d0c1d8a1
commit 64dd619da8
2 changed files with 30 additions and 11 deletions

View File

@ -4,6 +4,23 @@
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 #2>/dev/null
fi
tmux has-session -t $SESSION_NAME:$PROJECT 2>/dev/null
if [ $? != 0 ]; then
tmux new-window -t $SESSION_NAME: -n $PROJECT -d -c $SELECTED
fi
tmux switch-client -t $SESSION_NAME:$PROJECT
# Close tmux popup if any
tmux display-popup -C
}
declare -A CUSTOM_SESSIONS
CUSTOM_SESSIONS[Projects]=Halia
@ -13,17 +30,18 @@ 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]}")
tmux has-session -t $SESSION_NAME 2>/dev/null
if [ $? != 0 ]; then
tmux new-session -s $SESSION_NAME -d -n $PROJECT #2>/dev/null
fi
while getopts ":l" option; do
case $option in
l)
tmux send-keys 'cd $SELECTED' Enter
tmux has-session -t $SESSION_NAME:$PROJECT 2>/dev/null
if [ $? != 0 ]; then
tmux new-window -t $SESSION_NAME: -n $PROJECT -d -c $SELECTED
fi
# Close tmux popup if any
tmux display-popup -C
;;
*)
move_pane
;;
esac
done
tmux switch-client -t $SESSION_NAME:$PROJECT
# Close tmux popup if any
tmux display-popup -C

View File

@ -79,6 +79,7 @@ bind-key S command-prompt -p "Name of new session: " "new-session -s '%%'"
unbind o
bind-key o display-popup "tmux-projectinator"
bind-key O display-popup "tmux-projectinator -l"
# Quick pane resizing using arrow keys
bind-key -r H resize-pane -L 5