Skip to content

Instantly share code, notes, and snippets.

@naranyala
Created November 15, 2023 10:21
Show Gist options
  • Save naranyala/fdcd5a8b2e86f354fd0befef88b7c433 to your computer and use it in GitHub Desktop.
Save naranyala/fdcd5a8b2e86f354fd0befef88b7c433 to your computer and use it in GitHub Desktop.
#!/bin/bash
# INFO:
# using fzf to show tmux-session-list
# select and kill the selected-session
# Get a list of active tmux sessions
tmux_list=$(tmux list-sessions -F "#S")
# Check if there are no active sessions
if [ -z "$tmux_list" ]; then
echo "No active tmux sessions found."
exit 1
fi
# Use fzf to select a tmux session
selected_session=$(echo "$tmux_list" | fzf --reverse --prompt="Select a tmux session: ")
# Check if a selection is made
if [ -n "$selected_session" ]; then
# Confirm before killing the selected tmux session
read -r -p "Confirm: Kill tmux session '$selected_session'? (y/n): " response
if [[ "$response" =~ ^[Yy]$ ]]; then
tmux kill-session -t "$selected_session"
echo "Session '$selected_session' killed."
else
echo "Session not killed. Exiting."
exit 1
fi
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