Skip to content

Instantly share code, notes, and snippets.

@naranyala
Last active November 27, 2023 09:45
Show Gist options
  • Save naranyala/ef1efb89e085e2fbfe3e3a9b5f328a8f to your computer and use it in GitHub Desktop.
Save naranyala/ef1efb89e085e2fbfe3e3a9b5f328a8f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script to switch tmux sessions using fzf
# Get a list of active tmux sessions (excluding the current session)
session_list=$(tmux list-sessions | sed -E 's/:.*$//' | grep -v "^$(tmux display-message -p '#S')\$")
# Check if there are no active sessions
if [ -z "$session_list" ]; then
echo "No other active tmux sessions found."
exit 1
fi
# Use fzf to select a tmux session
selected_session=$(echo "$session_list" | fzf --reverse)
# Check if a selection is made
if [ -n "$selected_session" ]; then
# Switch to the selected tmux session
tmux switch-client -t "$selected_session"
echo "Switched to tmux session '$selected_session'."
else
echo "No session selected. Exiting."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment