aboutsummaryrefslogtreecommitdiff
path: root/scripts/tmux_selector.sh
blob: 3928df6ad52cd0ff3fce76e01d80cac7f036caac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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