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