From 02f617375433832d677426386eed9f9fe46aae3c Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 14 Nov 2023 00:14:35 +0100 Subject: [PATCH] fix(tmux): Project opener always use user base path --- .bin/tmux-projectinator | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/.bin/tmux-projectinator b/.bin/tmux-projectinator index 33b32e4..6a877b7 100755 --- a/.bin/tmux-projectinator +++ b/.bin/tmux-projectinator @@ -7,15 +7,15 @@ 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 + tmux new-session -s $SESSION_NAME -d -n $PROJECT_NAME -c $PROJECT_PATH fi - tmux has-session -t $SESSION_NAME:$PROJECT 2>/dev/null + tmux has-session -t $SESSION_NAME:$PROJECT_NAME 2>/dev/null if [ $? != 0 ]; then - tmux new-window -t $SESSION_NAME: -n $PROJECT -d -c $1 + tmux new-window -t $SESSION_NAME: -n $PROJECT_NAME -d -c $PROJECT_PATH fi - tmux switch-client -t $SESSION_NAME:$PROJECT + tmux switch-client -t $SESSION_NAME:$PROJECT_NAME # Close tmux popup if any tmux display-popup -C @@ -24,16 +24,20 @@ move_pane () { 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) +PROJECT_LIST=$(find ~/* -name .git -type d -prune 2>/dev/null) -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]}") +SELECTED=$(echo $PROJECT_LIST | sed 's/\/.git/\n/g' | sed "s/$(echo $HOME | sed 's/\//\\\//g')//" | cut -d'/' -f2- | fzf) + +PROJECT_PATH=$(echo $PROJECT_LIST | sed 's/\/.git/\n/g' | grep $SELECTED) +PROJECT_ROOT=$(echo $SELECTED | cut -d '/' -f1) +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 $SELECTED" Enter + tmux send-keys "cd $PROJECT_PATH" Enter # Close tmux popup if any tmux display-popup -C