-
Notifications
You must be signed in to change notification settings - Fork 1
/
paste.tmux
executable file
·59 lines (49 loc) · 1.56 KB
/
paste.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
#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HELPERS_DIR="${CURRENT_DIR}/scripts"
# shellcheck source=scripts/helpers.sh
source "${HELPERS_DIR}/helpers.sh"
set_paste_error_bindings() {
local key_set
local mouse_key_set
key_set="$(paste_key)"
mouse_key_set="$(paste_mouse_key)"
if [[ ! -z "$mouse_key_set" ]]; then
tmux bind-key -T root "$mouse_key_set" display-message "Error! tmux-paste dependencies not installed!"
fi
# Don't change the default for ] as it should still work within tmux
if [[ ! -z "$key_set" && ! "$key_set" == ']' ]]; then
tmux bind-key "$key_set" display-message "Error! tmux-paste dependencies not installed!"
fi
}
error_handling_if_paste_cmd_not_present() {
local paste_command="$1"
if [[ -z "$paste_command" ]]; then
set_paste_error_bindings
exit 0
fi
}
set_paste_bindings() {
local key_set
local mouse_key_set
key_set="$(paste_key)"
mouse_key_set="$(paste_mouse_key)"
local paste_command="$1"
# shellcheck disable=SC2016
local set_buffer='tmux set-buffer "$('
local paste_buffer=')"; tmux paste-buffer'
if [[ ! -z "$mouse_key_set" ]]; then
tmux bind-key -T root "$mouse_key_set" run-shell -b "$set_buffer$paste_command$paste_buffer"
fi
if [[ ! -z "$key_set" ]]; then
tmux bind-key "$key_set" run-shell -b "$set_buffer$paste_command$paste_buffer"
fi
}
main() {
local paste_command
# shellcheck disable=SC2119
paste_command="$(clipboard_paste_cmd)"
error_handling_if_paste_cmd_not_present "$paste_command"
set_paste_bindings "$paste_command"
}
main