@@ -5,6 +5,11 @@ resolve_bin() {
55 local name=" $1 "
66 shift
77
8+ if command -v " $name " > /dev/null 2>&1 ; then
9+ command -v " $name "
10+ return 0
11+ fi
12+
813 local candidate
914 for candidate in " $@ " ; do
1015 [[ -n " $candidate " && -x " $candidate " ]] && {
@@ -13,44 +18,86 @@ resolve_bin() {
1318 }
1419 done
1520
16- command -v " $name " 2> /dev/null || true
21+ return 0
1722}
1823
24+ TMUX_BIN=" ${TMUX_BIN:- $(resolve_bin tmux " /opt/homebrew/bin/tmux" " /run/current-system/sw/bin/tmux" " $HOME /.nix-profile/bin/tmux" )} "
25+ BASH_BIN=" ${BASH_BIN:- $(resolve_bin bash " /bin/bash" " /usr/bin/bash" " $HOME /.nix-profile/bin/bash" )} "
1926SESH_BIN=" ${SESH_BIN:- $(resolve_bin sesh " /opt/homebrew/bin/sesh" " /run/current-system/sw/bin/sesh" " $HOME /.nix-profile/bin/sesh" )} "
2027FZF_TMUX_BIN=" ${FZF_TMUX_BIN:- $(resolve_bin fzf-tmux " /opt/homebrew/bin/fzf-tmux" " /run/current-system/sw/bin/fzf-tmux" " $HOME /.nix-profile/bin/fzf-tmux" )} "
2128SCRIPT_DIR=${TMUX_HOME:- $HOME / .config/ tmux}
22- CUR_SESS=$( tmux display-message -p ' #S' 2> /dev/null)
23- CUR_DIR=$( tmux display-message -p ' #{pane_current_path}' 2> /dev/null)
29+ CUR_SESS=" "
30+ CUR_DIR=" "
31+ if [[ -n " $TMUX_BIN " ]]; then
32+ CUR_SESS=$( " $TMUX_BIN " display-message -p ' #S' 2> /dev/null || true)
33+ CUR_DIR=$( " $TMUX_BIN " display-message -p ' #{pane_current_path}' 2> /dev/null || true)
34+ fi
2435CUR_DIR_SHORT=${CUR_DIR/# $HOME / \~ }
2536
37+ tmux_message () {
38+ local message=" $1 "
39+ if [[ -n " $TMUX_BIN " ]]; then
40+ " $TMUX_BIN " display-message " $message "
41+ else
42+ printf ' %s\n' " $message " >&2
43+ fi
44+ }
45+
2646[[ -n " $SESH_BIN " ]] || {
27- tmux display-message " sesh-picker: sesh not found"
47+ tmux_message " sesh-picker: sesh not found"
2848 exit 1
2949}
3050
3151[[ -n " $FZF_TMUX_BIN " ]] || {
32- tmux display-message " sesh-picker: fzf-tmux not found"
52+ tmux_message " sesh-picker: fzf-tmux not found"
3353 exit 1
3454}
3555
3656export SESH_BIN
3757
3858SESSION=$(
39- " $SCRIPT_DIR /sesh-all.sh" | " $FZF_TMUX_BIN " -p 80%,70% \
59+ " $BASH_BIN " " $ SCRIPT_DIR /sesh-all.sh" | " $FZF_TMUX_BIN " -p 80%,70% \
4060 --ansi \
4161 --no-sort \
4262 --border-label " sesh " \
4363 --prompt " > " \
4464 --header " ^a all ^t tmux ^c configs ^x zoxide ^d kill" \
4565 --bind " tab:down,btab:up" \
46- --bind " ctrl-a:change-prompt(> )+reload($SCRIPT_DIR /sesh-all.sh)" \
66+ --bind " ctrl-a:change-prompt(> )+reload($BASH_BIN $ SCRIPT_DIR /sesh-all.sh)" \
4767 --bind " ctrl-t:change-prompt(tmux> )+reload($SESH_BIN list -t | grep -vxF '$CUR_SESS ' | awk '{printf \"\\ 033[35m■\\ 033[0m %s\\ n\" , \$ 0}')" \
4868 --bind " ctrl-c:change-prompt(configs> )+reload($SESH_BIN list -c | grep -vxF '$CUR_SESS ' | awk '{printf \"\\ 033[33m□\\ 033[0m %s\\ n\" , \$ 0}')" \
49- --bind " ctrl-x:change-prompt(zoxide> )+reload($SCRIPT_DIR /zoxide-list.sh | grep -vxF '$CUR_DIR_SHORT ' | awk '{printf \"\\ 033[34m›\\ 033[0m %s\\ n\" , \$ 0}')" \
50- --bind " ctrl-d:execute(tmux kill-session -t {2..})+change-prompt(> )+reload($SCRIPT_DIR /sesh-all.sh)"
69+ --bind " ctrl-x:change-prompt(zoxide> )+reload($BASH_BIN $ SCRIPT_DIR /zoxide-list.sh | grep -vxF '$CUR_DIR_SHORT ' | awk '{printf \"\\ 033[34m›\\ 033[0m %s\\ n\" , \$ 0}')" \
70+ --bind " ctrl-d:execute(tmux kill-session -t {2..})+change-prompt(> )+reload($BASH_BIN $ SCRIPT_DIR /sesh-all.sh)"
5171)
5272
5373# Strip ANSI escape codes, then the symbol prefix
54- SESSION=$( printf ' %s' " $SESSION " | sed ' s/\x1b\[[0-9;]*m//g; s/^[■□›] //' )
74+ strip_ansi () {
75+ local input=" $1 "
76+ local output=" "
77+ local ch=" "
78+
79+ while [[ -n " $input " ]]; do
80+ ch=${input: 0: 1}
81+ if [[ " $ch " == $' \e ' && ${input: 1: 1} == ' [' ]]; then
82+ input=${input: 2}
83+ while [[ -n " $input " ]]; do
84+ ch=${input: 0: 1}
85+ input=${input: 1}
86+ [[ " $ch " == ' m' ]] && break
87+ done
88+ continue
89+ fi
90+
91+ output+=" $ch "
92+ input=${input: 1}
93+ done
94+
95+ printf ' %s' " $output "
96+ }
97+
98+ SESSION=$( strip_ansi " $SESSION " )
99+ SESSION=${SESSION# ■ }
100+ SESSION=${SESSION# □ }
101+ SESSION=${SESSION# › }
55102[ -n " $SESSION " ] && " $SESH_BIN " connect " $SESSION "
56103exit 0
0 commit comments