-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathetmux-session-finder.sh
executable file
·63 lines (50 loc) · 1.2 KB
/
etmux-session-finder.sh
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env zsh
# from https://github.com/siadat/session-finder
set -e
file_sessions() {
local socket
local sessions
local paths
local etmux_path
local files
if [ -z $ETMUX_PATH ]; then
etmux_path=~/.etmux-sessions
else
etmux_path=$ETMUX_PATH
fi
paths=(`echo $etmux_path | tr ":" "\n"`)
for x in $paths; do
if [ -d "$x" ]; then
cd $x
ls -1 $x
fi
done
}
active_sessions() {
tmux ls -F '#{session_attached} #{?session_last_attached,,0}#{session_last_attached} #{session_name}' 2> /dev/null | sort -r | perl -pe 's/^[0-9]+ [0-9]+ //'
}
sessions() {
sessions=("${(@f)$(active_sessions)}")
files=("${(@f)$(file_sessions)}")
for s in $sessions; do
files=("${(@)files:#$s}")
done
if [ "$TMUX" ]; then
current=$sessions[1]
sessions=("${(@)sessions:#$current}")
fi
for s in $sessions; do
echo "✓ $s"
done
for f in $files; do
echo " $f"
done
}
prompt="find/create session> "
fzf_out=$(sessions | fzf --print-query --prompt="$prompt" || true)
line_count=$(echo "$fzf_out" | wc -l)
session_name=$(echo "$fzf_out" | tail -n1)
command=$(echo "$session_name" | awk '{ print $1 }')
if [ "$session_name" ]; then
etmux ${session_name:2}
fi