-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrat_tmux-navigator.sh
executable file
·132 lines (118 loc) · 2.52 KB
/
rat_tmux-navigator.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
if [[ "$1" == "rat" ]]; then
current_window=$(ratpoison -c 'info' | sed 's/(.*).*(\(.*\))/\1/'\
| tr '[:upper:]' '[:lower:]')
elif [[ "$1" == "tmux" ]];then
window_bottom=$(tmux list-panes -F "#{window_height}" | head -n1)
window_right=$(tmux list-panes -F "#{window_width}" | head -n1)
window_bottom=$(($window_bottom - 1))
window_right=$(($window_right - 1))
pane=$(tmux list-panes -F "#{pane_left} #{pane_right} #{pane_top} #{pane_bottom} #{pane_active}" | grep '.* 1$')
pane_left=$(echo "$pane" | cut -d' ' -f 1)
pane_right=$(echo "$pane" | cut -d' ' -f 2)
pane_top=$(echo "$pane" | cut -d' ' -f 3)
pane_bottom=$(echo "$pane" | cut -d' ' -f 4)
fi
function rat_up
{
if [[ "$current_window" == "alacritty" ]];
then
ratpoison -c 'meta C-k'
else
ratpoison -c 'focusup'
fi
}
function rat_down
{
if [[ "$current_window" == "alacritty" ]];
then
ratpoison -c 'meta C-j'
else
ratpoison -c 'focusdown'
fi
}
function rat_right
{
if [[ "$current_window" == "alacritty" ]];
then
ratpoison -c 'meta C-l'
else
~/.scripts/ratpoison/frame-mon_navigator.sh right
fi
}
function rat_left
{
if [[ "$current_window" == "alacritty" ]];
then
ratpoison -c 'meta C-h'
else
~/.scripts/ratpoison/frame-mon_navigator.sh left
fi
}
function tmux_up
{
if [[ $pane_top -eq 0 ]];
then
ratpoison -c 'focusup'
else
tmux select-pane -U
fi
}
function tmux_down
{
if [[ $pane_bottom -eq $window_bottom ]];
then
ratpoison -c 'focusdown'
else
tmux select-pane -D
fi
}
function tmux_right
{
if [[ $pane_right -eq $window_right ]];
then
~/.scripts/ratpoison/frame-mon_navigator.sh right
else
tmux select-pane -R
fi
}
function tmux_left
{
if [[ $pane_left -eq 0 ]];
then
~/.scripts/ratpoison/frame-mon_navigator.sh left
else
tmux select-pane -L
fi
}
if [[ "$1" == "rat" ]];then
case "$2" in
'up')
rat_up
;;
'down')
rat_down
;;
'right')
rat_right
;;
'left')
rat_left
;;
esac
elif [[ "$1" == "tmux" ]];then
case "$2" in
'up')
tmux_up
;;
'down')
tmux_down
;;
'right')
tmux_right
;;
'left')
tmux_left
;;
esac
fi