From e6475a8e8becbf693fd4edbff1cee579315ffb32 Mon Sep 17 00:00:00 2001 From: Matthew Owens Date: Thu, 20 Jan 2022 12:20:00 +0000 Subject: [PATCH] updated project script --- proj | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/proj b/proj index a935215..e574e1e 100755 --- a/proj +++ b/proj @@ -11,26 +11,50 @@ fi folderPath=$(find $HOME/git/ -maxdepth 3 -type d -name $1) folderCount=$(find $HOME/git/ -maxdepth 3 -type d -name $1 | wc -l) +running=$(tmux ls | grep $1 | wc -l) # if 1 we have a session running already -if [ $folderCount -gt 1 ]; then - echo "err: multiple possible projects found for '$1'" - echo $folderPath - exit +if [ $folderCount -gt 1 ] && [ $running -ne 1 ]; then + count=1 + echo "multiple possible projects found for '$1', pick one" + + for var in $folderPath + do + echo -e "\t$count) '$var'" + ((count++)) + done + + read -p "Enter a path number: " selected + while [[ $selected -lt 1 || $selected -gt $folderCount ]]; do + read -p "Bad value, try again: " selected + done + + count=1 + for var in $folderPath + do + if [[ $count -eq $selected ]]; then + path=$var + fi + ((count++)) + done + echo "selected: $path" elif [ $folderCount -eq 0 ]; then echo "err: no possible projects found for '$1'" exit +else + path=$folderPath fi # is the session already running? -if [ $(tmux ls | grep $1 | wc -l) -eq 1 ]; then +if [ $running -eq 1 ]; then tmux new-session -A -s $1 exit else - cd $folderPath + cd $path tmux new-session -d -s $1 + #tmux new-session -A -s $1 tmux rename-window src tmux send-keys "cd src;clear" ENTER - tmux new-window -n build -c $folderPath + tmux new-window -n build -c $path tmux select-window -t src tmux -2 attach-session -d fi -- 2.20.1