aboutsummaryrefslogtreecommitdiff
path: root/dotfiles
diff options
context:
space:
mode:
Diffstat (limited to 'dotfiles')
-rwxr-xr-xdotfiles/common/.local/bin/tmux-util39
1 files changed, 38 insertions, 1 deletions
diff --git a/dotfiles/common/.local/bin/tmux-util b/dotfiles/common/.local/bin/tmux-util
index 5e0ce85..4669b03 100755
--- a/dotfiles/common/.local/bin/tmux-util
+++ b/dotfiles/common/.local/bin/tmux-util
@@ -36,6 +36,40 @@ EOF
}
# -----------------------------------------------------------------------------
+# pick
+# -----------------------------------------------------------------------------
+
+cmd_pick() {
+ local sessions
+ sessions=$(tmux list-sessions \
+ -F '#{session_attached} #{session_name}' 2>/dev/null || true)
+ if [ -z "$sessions" ]; then
+ echo "No tmux sessions to pick from."
+ return 0
+ fi
+
+ # Format for fzf: "<state> <name>" — name is the second field of the
+ # selection line, which we recover after fzf returns.
+ local choice
+ choice=$(echo "$sessions" | awk '{
+ state = ($1 == "1") ? "attached" : "detached"
+ printf "%-9s %s\n", state, $2
+ }' | fzf --header="Pick a tmux session" | awk '{print $2}')
+
+ if [ -z "$choice" ]; then
+ # User cancelled (Ctrl-C or Esc); fzf exits 130, the pipeline
+ # returns empty.
+ return 0
+ fi
+
+ if [ -n "${TMUX:-}" ]; then
+ tmux switch-client -t "$choice"
+ else
+ tmux attach-session -t "$choice"
+ fi
+}
+
+# -----------------------------------------------------------------------------
# find
# -----------------------------------------------------------------------------
@@ -204,7 +238,10 @@ main() {
find)
cmd_find "$@"
;;
- pick|rename)
+ pick)
+ cmd_pick "$@"
+ ;;
+ rename)
echo "tmux-util: subcommand '$sub' is not implemented yet" >&2
return 2
;;