Skip to content

Commit

Permalink
adding tmux shell cmd
Browse files Browse the repository at this point in the history
should probably use one of the tmux plugins, but chatgpt helped with me with this one and it's easy to understand
  • Loading branch information
iloveitaly committed May 21, 2023
1 parent 820ff0b commit 68e26ed
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .tmux-shell.sh
@@ -0,0 +1,33 @@
#!/usr/bin/env zsh

# initial session name
session_name=${PWD:t}

# session counter
counter=0

while [[ $counter -lt 10 ]]; do
if [[ $counter -gt 0 ]]; then
session="${session_name} $counter"
else
session="${session_name}"
fi

# if the session doesn't exist, create it
if ! tmux has-session -t "$session" 2>/dev/null; then
tmux new -ADs "$session"
break
fi

# if the session exists but isn't attached, attach it
if [ -z "$(tmux list-sessions -F "#{session_name} #{session_attached}" | grep "^$session 1")" ]; then
tmux attach -t "$session"
break
fi

counter=$((counter + 1))
done

if [[ $counter -ge 10 ]]; then
echo "Could not find an unattached session after 10 attempts."
fi

0 comments on commit 68e26ed

Please sign in to comment.