-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
ssh-split.tmux
executable file
·118 lines (99 loc) · 2.35 KB
/
ssh-split.tmux
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
#!/usr/bin/env bash
get_tmux_option() {
local option="$1"
local default_value="$2"
local raw_value
raw_value=$(tmux show-option -gqv "$option")
echo "${raw_value:-$default_value}"
}
main() {
local -a extra_args
local current_dir
local fail
local hkey
local noenv
local noshell
local script_path
local verbose
local debug
local vkey
local wkey
local keep_cwd
local keep_remote_cwd
debug="$(get_tmux_option @ssh-split-debug)"
verbose="$(get_tmux_option @ssh-split-verbose)"
fail="$(get_tmux_option @ssh-split-fail)"
keep_cwd="$(get_tmux_option @ssh-split-keep-cwd)"
keep_remote_cwd="$(get_tmux_option @ssh-split-keep-remote-cwd)"
noenv="$(get_tmux_option @ssh-split-no-env)"
noshell="$(get_tmux_option @ssh-split-no-shell)"
stripcmd="$(get_tmux_option @ssh-split-strip-cmd)"
hkey="$(get_tmux_option @ssh-split-h-key)"
vkey="$(get_tmux_option @ssh-split-v-key)"
wkey="$(get_tmux_option @ssh-split-w-key)"
case "$keep_cwd" in
true|1|yes)
# Double quote path since it may contain spaces.
# Especially when the current dir gets deleted, tmux then
# appends " (removed)"
extra_args+=(-c "'#{pane_current_path}'")
;;
esac
case "$keep_remote_cwd" in
true|1|yes)
extra_args+=(--keep-remote-cwd)
;;
esac
case "$fail" in
true|1|yes)
extra_args+=(--fail)
;;
esac
case "$noenv" in
true|1|yes)
extra_args+=(--no-env)
;;
esac
case "$noshell" in
true|1|yes)
extra_args+=(--no-shell)
;;
esac
case "$stripcmd" in
true|1|yes)
extra_args+=(--strip-cmd)
;;
esac
case "$verbose" in
true|1|yes)
extra_args+=(--verbose)
;;
esac
case "$debug" in
true|1|yes)
extra_args+=(--debug)
;;
esac
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
script_path="${current_dir}/scripts/tmux-ssh-split.sh"
if [[ -n "$hkey" ]]
then
tmux unbind "$hkey"
tmux bind-key "$hkey" run "${script_path} ${extra_args[*]} -h"
fi
if [[ -n "$vkey" ]]
then
tmux unbind "$vkey"
tmux bind-key "$vkey" run "${script_path} ${extra_args[*]} -v"
fi
if [[ -n "$wkey" ]]
then
tmux unbind "$wkey"
tmux bind-key "$wkey" run "${script_path} ${extra_args[*]} --window"
fi
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
then
main
fi
# vim: set ft=bash et ts=2 sw=2 :