Skip to content

Instantly share code, notes, and snippets.

@Rayquaza01
Created July 10, 2024 21:03
Show Gist options
  • Select an option

  • Save Rayquaza01/073632ef803cfd639406f72d842224fb to your computer and use it in GitHub Desktop.

Select an option

Save Rayquaza01/073632ef803cfd639406f72d842224fb to your computer and use it in GitHub Desktop.
#!/bin/bash
# if inside a tmux session, don't do anything
if [ -z "$TMUX" ]; then
# get the session name of the first session that isn't attached
FREE_SESSION=$(tmux ls 2>/dev/null | grep -v "(attached)$" | cut -f1 -d: | head -n 1)
# if no free sessions, make a new one
# otherwise attach to it
if [ -z "$FREE_SESSION" ]; then
tmux new && exit
else
tmux attach -t "$FREE_SESSION" && exit
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment