From d8ce34981ecc54f444cae2faf7757f25b28a93f2 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Tue, 2 Apr 2024 23:24:41 +0200 Subject: tmux selector first draft --- scripts/tmux_selector.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 scripts/tmux_selector.sh (limited to 'scripts') diff --git a/scripts/tmux_selector.sh b/scripts/tmux_selector.sh new file mode 100755 index 0000000..3928df6 --- /dev/null +++ b/scripts/tmux_selector.sh @@ -0,0 +1,28 @@ +#!/bin/bash +shopt -s extglob + +readonly TMUX_FORMAT='#{session_id};#{session_attached};#{session_name}' + +OPTIONS=$( +echo new +while IFS=';' read -r ID ATTACHED NAME; do + printf "%s\t|" "$ID" + printf " %s" "$NAME" + test $ATTACHED -ge 1 && printf " (attached)" + + printf "\n" +done <<< "$(tmux ls -F "$TMUX_FORMAT")" +) + +CHOICE=$(fzf <<< "$OPTIONS" | awk -F'|' '{ print $1 }') +test -z "$CHOICE" && exit 1 + +echo $CHOICE + +case $CHOICE in + $+([0-9])* ) + tmux attach -t $CHOICE ;; + new) tmux ;; + *) + exit 1;; +esac -- cgit v1.2.3