2
2
3
3
CURRENT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
4
4
5
+ # shellcheck source=./scripts/helpers.sh
5
6
source " $CURRENT_DIR /scripts/helpers.sh"
6
7
7
8
default_open_key=" o"
@@ -11,29 +12,21 @@ default_open_editor_key="C-o"
11
12
open_editor_option=" @open-editor"
12
13
open_editor_override=" @open-editor-command"
13
14
15
+ open_opener_override=" @open-opener-command"
16
+
14
17
command_exists () {
15
18
local command=" $1 "
16
19
type " $command " > /dev/null 2>&1
17
20
}
18
21
19
22
is_osx () {
20
- local platform=$( uname)
21
- [ " $platform " == " Darwin" ]
23
+ [ " $( uname) " == " Darwin" ]
22
24
}
23
25
24
26
is_cygwin () {
25
27
[[ " $( uname) " =~ CYGWIN ]]
26
28
}
27
29
28
- get_editor_from_the_env_var () {
29
- if [ -z $EDITOR ]; then
30
- # $EDITOR not set, fallback
31
- echo " vi"
32
- else
33
- echo " $EDITOR "
34
- fi
35
- }
36
-
37
30
command_generator () {
38
31
local command_string=" $1 "
39
32
echo " xargs -I {} tmux run-shell -b 'cd #{pane_current_path}; $command_string \" {}\" > /dev/null'"
@@ -47,12 +40,15 @@ search_command_generator() {
47
40
}
48
41
49
42
generate_open_command () {
50
- if is_osx; then
51
- echo " $( command_generator " open" ) "
43
+ local opener
44
+ if opener=" $( get_tmux_option " $open_opener_override " ' ' ) " && [ -n " ${opener-} " ]; then
45
+ command_generator " ${opener} "
46
+ elif is_osx; then
47
+ command_generator " open"
52
48
elif is_cygwin; then
53
- echo " $( command_generator " cygstart" ) "
49
+ command_generator " cygstart"
54
50
elif command_exists " xdg-open" ; then
55
- echo " $( command_generator " xdg-open" ) "
51
+ command_generator " xdg-open"
56
52
else
57
53
# error command for Linux machines when 'xdg-open' not installed
58
54
" $CURRENT_DIR /scripts/tmux_open_error_message.sh" " xdg-open"
@@ -61,12 +57,15 @@ generate_open_command() {
61
57
62
58
generate_open_search_command () {
63
59
local engine=" $1 "
64
- if is_osx; then
65
- echo " $( search_command_generator " open" " $engine " ) "
60
+ local opener
61
+ if opener=" $( get_tmux_option " $open_opener_override " ' ' ) " && [ -n " ${opener-} " ]; then
62
+ search_command_generator " $opener " " $engine "
63
+ elif is_osx; then
64
+ search_command_generator " open" " $engine "
66
65
elif is_cygwin; then
67
- echo " $( command_generator " cygstart" ) "
66
+ command_generator " cygstart"
68
67
elif command_exists " xdg-open" ; then
69
- echo " $( search_command_generator " xdg-open" " $engine " ) "
68
+ search_command_generator " xdg-open" " $engine "
70
69
else
71
70
# error command for Linux machines when 'xdg-open' not installed
72
71
" $CURRENT_DIR /scripts/tmux_open_error_message.sh" " xdg-open"
@@ -76,16 +75,19 @@ generate_open_search_command() {
76
75
# 1. write a command to the terminal, example: 'vim -- some_file.txt'
77
76
# 2. invoke the command by pressing enter/C-m
78
77
generate_editor_command () {
79
- local environment_editor=$( get_editor_from_the_env_var)
80
- local editor=$( get_tmux_option " $open_editor_override " " $environment_editor " )
78
+ local environment_editor=" ${EDITOR:- vi} "
79
+ local editor
80
+ editor=$( get_tmux_option " $open_editor_override " " $environment_editor " )
81
81
# vim freezes terminal unless there's the '--' argument. Other editors seem
82
82
# to be fine with it (textmate [mate], light table [table]).
83
83
echo " xargs -I {} tmux send-keys '$editor -- \" {}\" '; tmux send-keys 'C-m'"
84
84
}
85
85
86
86
set_copy_mode_open_bindings () {
87
- local open_command=" $( generate_open_command) "
88
- local key_bindings=$( get_tmux_option " $open_option " " $default_open_key " )
87
+ local open_command
88
+ open_command=" $( generate_open_command) "
89
+ local key_bindings
90
+ key_bindings=$( get_tmux_option " $open_option " " $default_open_key " )
89
91
local key
90
92
for key in $key_bindings ; do
91
93
if tmux-is-at-least 2.4; then
@@ -99,8 +101,10 @@ set_copy_mode_open_bindings() {
99
101
}
100
102
101
103
set_copy_mode_open_editor_bindings () {
102
- local editor_command=" $( generate_editor_command) "
103
- local key_bindings=$( get_tmux_option " $open_editor_option " " $default_open_editor_key " )
104
+ local editor_command
105
+ editor_command=" $( generate_editor_command) "
106
+ local key_bindings
107
+ key_bindings=" $( get_tmux_option " $open_editor_option " " $default_open_editor_key " ) "
104
108
local key
105
109
for key in $key_bindings ; do
106
110
if tmux-is-at-least 2.4; then
@@ -114,13 +118,14 @@ set_copy_mode_open_editor_bindings() {
114
118
}
115
119
116
120
set_copy_mode_open_search_bindings () {
117
- local stored_engine_vars=" $( stored_engine_vars) "
121
+ local stored_engine_vars
122
+ stored_engine_vars=" $( stored_engine_vars) "
118
123
local engine_var
119
124
local engine
120
125
local key
121
126
122
127
for engine_var in $stored_engine_vars ; do
123
- engine=" $( get_engine " $engine_var " ) "
128
+ engine=" $( get_engine " $engine_var " ) " || continue
124
129
125
130
if tmux-is-at-least 2.4; then
126
131
tmux bind-key -T copy-mode-vi " $engine_var " send-keys -X copy-pipe-and-cancel " $( generate_open_search_command " $engine " ) "
0 commit comments