-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheckTmuxTargetExistence.sh
More file actions
executable file
·65 lines (53 loc) · 1.4 KB
/
Copy pathcheckTmuxTargetExistence.sh
File metadata and controls
executable file
·65 lines (53 loc) · 1.4 KB
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
64
65
#! /bin/bash
# exit code 0 if the SESSION:WINDOW.PANE / WINDOW.PANE / PANE target exists
# exit code non-zero if doesn't exist, etc.
if [ -z $1 ]; then
echo "No target supplied"
exit 1
else
t=$1
default_session_name="___not___set___"
if [[ -n "$TMUX_PANE" ]]; then
default_session_name=$(tmux list-panes -t "$TMUX_PANE" -F '#S' | head -n1)
fi
# what was passed in?
# tmux targets look like this:
# SESSION:WINDOW.PANE
# this script can accept any of these
if [[ $t == *":"* ]]; then
target_session=`echo "$t" | sed 's/\(.*\):.*/\1/'`
else
if [ $default_session_name != "___not___set___" ]; then
target_session=$default_session_name
else
echo "No session name supplied in target and outside of a tmux session; exiting"
exit 1
fi
fi
if [[ $t == *"."* ]]; then
target_window=`echo "$t" | sed 's/\(.*:\)*\(.*\)\..*/\2/'`
else
target_window=`tmux display-message -p '#W'`
fi
target_pane=`echo "$t" | sed 's/\(.*:\)*\(.*\.\)*\(.*\)/\3/'`
# echo "run against '${target_session}:${target_window}.${target_pane}'"
tmux has-session -t $target_session 2>/dev/null
if [ $? -eq 0 ]; then
tmux list-windows -F '#W' | grep -q "^$target_window\$"
if [ $? -eq 0 ]; then
tmux list-panes -F '#P' | grep -q "^$target_pane\$"
if [ $? -eq 0 ]; then
exit 0
else
# pane not found
exit 1
fi
else
# window not found
exit 1
fi
else
# sess not found
exit 1
fi
fi