Skip to content

Instantly share code, notes, and snippets.

@DanNYSPD
Last active August 9, 2023 07:42
Show Gist options
  • Save DanNYSPD/856ea596a0e51da1000d97cbe7415449 to your computer and use it in GitHub Desktop.
Save DanNYSPD/856ea596a0e51da1000d97cbe7415449 to your computer and use it in GitHub Desktop.
if [[ -z "$WORKSPACE_DIR" ]]; then
if [[ -d "/var/www/html" ]]; then
WORKSPACE_DIR='/var/www/html'
fi
fi
workspaces=$(echo "$WORKSPACE_DIR" | tr ':' ' ') #in case multiple projects open fast
#project=$(find $workspaces -maxdepth 1 -type d | fzf)
if [[ "$SHELL" =~ *zsh$ ]]; then
project=$(find ${=workspaces} -maxdepth 1 -type d | fzf)
else
project=$(find $workspaces -maxdepth 1 -type d | fzf)
fi
#find @("${workspaces}") -type d
if [[ ! -z "$project" ]]; then
echo "opening $project"
#code $project
else
echo "no project was selected"
return 1
fi
SESION_NAME=$(basename $project)
if tmux list-sessions &>/dev/null; then
TMUX_RUNNING=0
echo "listing"
#TODO: , Open a tmux custom session, ok course if it already exist just ask if we want to switch
EXIST=$(tmux list-sessions| grep $SESION_NAME -c)
echo "afeter"
else
TMUX_RUNNING=1
EXIST=0
fi
if [[ -z "$TMUX" ]]; then
if [[ $EXIST -eq 0 ]]; then
echo "no tmux, creating"
tmux new -s $SESION_NAME -c $project -d
else
echo "SESION $SESION_NAME already exist"
#tmux attach-session -t $SESION_NAME
tmux attach -t "$SESION_NAME"
fi
else
#echo "already in a tmux"
if [[ $EXIST -eq 0 ]]; then
#echo "not exist, create"
#-d option avoid attaching to the new session
#tmux new-session -d -s $SESION_NAME -c $project
tmux new -d -s $SESION_NAME -c $project
tmux switch-client -t $SESION_NAME
else
tmux switch-client -t $SESION_NAME
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment