Skip to content

Instantly share code, notes, and snippets.

@naranyala
Created November 15, 2023 10:21
Show Gist options
  • Save naranyala/7b3eaf9a3127b52da8b4ff092fe908c2 to your computer and use it in GitHub Desktop.
Save naranyala/7b3eaf9a3127b52da8b4ff092fe908c2 to your computer and use it in GitHub Desktop.
#!/bin/bash
# INFO:
# using fzf to show tmux-window-list (active session)
# select and kill the selected-window
# Get the current tmux session
TMUX_SESSION=$(tmux display-message -p '#S')
# Get a list of windows in the current session
tmux_windows=$(tmux list-windows -t "$TMUX_SESSION" -F "#I:#W")
# Check if there are no windows in the current session
if [ -z "$tmux_windows" ]; then
echo "No windows found in the current session '$TMUX_SESSION'. Exiting."
exit 1
fi
# Use fzf to select a window
selected_window=$(echo "$tmux_windows" | fzf --reverse --prompt="Select a window: " | cut -d ':' -f2)
if [ -n "$selected_window" ]; then
# Kill the selected tmux window
tmux kill-window -t "$TMUX_SESSION:$selected_window"
echo "Window '$selected_window' in session '$TMUX_SESSION' killed."
else
echo "No window selected. Exiting."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment