From 754d7c20d13a424daa0389da54c4a6454ef886a7 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Fri, 17 Nov 2023 09:47:06 +0100 Subject: [PATCH] feat(tmux): Add debug mode to projectinator --- .bin/tmux-projectinator | 52 ++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/.bin/tmux-projectinator b/.bin/tmux-projectinator index 6a877b7..1c838df 100755 --- a/.bin/tmux-projectinator +++ b/.bin/tmux-projectinator @@ -4,15 +4,43 @@ set -o emacs bind '"\e": "\C-W\c-d"' -move_pane () { +OPEN_MODE="new_pane" + +while getopts ":l:v" option; do + case $option in + l) + OPEN_MODE="local" + ;; + v) + VERBOSE=true + ;; + esac +done + +debug () { + if [ "$VERBOSE" = true ]; then + echo $1 + fi +} + +open_local () { + tmux send-keys "cd $PROJECT_PATH" Enter + + # Close tmux popup if any + tmux display-popup -C +} + +open_new_pane () { tmux has-session -t $SESSION_NAME 2>/dev/null if [ $? != 0 ]; then + debug "Session $SESSION_NAME missing, creating it." tmux new-session -s $SESSION_NAME -d -n $PROJECT_NAME -c $PROJECT_PATH fi tmux has-session -t $SESSION_NAME:$PROJECT_NAME 2>/dev/null if [ $? != 0 ]; then - tmux new-window -t $SESSION_NAME: -n $PROJECT_NAME -d -c $PROJECT_PATH + debug "Window $PROJECT_NAME in $SESSION_NAME not found, creating it." + tmux new-window -t $SESSION_NAME -n $PROJECT_NAME -d -c $PROJECT_PATH fi tmux switch-client -t $SESSION_NAME:$PROJECT_NAME @@ -34,15 +62,13 @@ PROJECT_NAME=$(echo $SELECTED | rev | cut -d '/' -f1 | rev) SESSION_NAME=$([ -z "${CUSTOM_SESSIONS[$PROJECT_ROOT]}" ] && echo "$PROJECT_ROOT" || echo "${CUSTOM_SESSIONS[$PROJECT_ROOT]}") -while getopts ":l" option; do - case $option in - l) - tmux send-keys "cd $PROJECT_PATH" Enter +debug "Project path is $PROJECT_PATH" - # Close tmux popup if any - tmux display-popup -C - ;; - esac -done - -if [ $OPTIND -eq 1 ]; then move_pane "$SELECTED"; fi +case $OPEN_MODE in + "new_pane") + open_new_pane + ;; + "local") + open_local + ;; +esac