22
33CURRENT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
44
5+ # shellcheck source=./scripts/helpers.sh
56source " $CURRENT_DIR /scripts/helpers.sh"
67
78default_open_key=" o"
@@ -11,29 +12,21 @@ default_open_editor_key="C-o"
1112open_editor_option=" @open-editor"
1213open_editor_override=" @open-editor-command"
1314
15+ open_opener_override=" @open-opener-command"
16+
1417command_exists () {
1518 local command=" $1 "
1619 type " $command " > /dev/null 2>&1
1720}
1821
1922is_osx () {
20- local platform=$( uname)
21- [ " $platform " == " Darwin" ]
23+ [ " $( uname) " == " Darwin" ]
2224}
2325
2426is_cygwin () {
2527 [[ " $( uname) " =~ CYGWIN ]]
2628}
2729
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-
3730command_generator () {
3831 local command_string=" $1 "
3932 echo " xargs -I {} tmux run-shell -b 'cd #{pane_current_path}; $command_string \" {}\" > /dev/null'"
@@ -47,12 +40,15 @@ search_command_generator() {
4740}
4841
4942generate_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"
5248 elif is_cygwin; then
53- echo " $( command_generator " cygstart" ) "
49+ command_generator " cygstart"
5450 elif command_exists " xdg-open" ; then
55- echo " $( command_generator " xdg-open" ) "
51+ command_generator " xdg-open"
5652 else
5753 # error command for Linux machines when 'xdg-open' not installed
5854 " $CURRENT_DIR /scripts/tmux_open_error_message.sh" " xdg-open"
@@ -61,12 +57,15 @@ generate_open_command() {
6157
6258generate_open_search_command () {
6359 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 "
6665 elif is_cygwin; then
67- echo " $( command_generator " cygstart" ) "
66+ command_generator " cygstart"
6867 elif command_exists " xdg-open" ; then
69- echo " $( search_command_generator " xdg-open" " $engine " ) "
68+ search_command_generator " xdg-open" " $engine "
7069 else
7170 # error command for Linux machines when 'xdg-open' not installed
7271 " $CURRENT_DIR /scripts/tmux_open_error_message.sh" " xdg-open"
@@ -76,16 +75,19 @@ generate_open_search_command() {
7675# 1. write a command to the terminal, example: 'vim -- some_file.txt'
7776# 2. invoke the command by pressing enter/C-m
7877generate_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 " )
8181 # vim freezes terminal unless there's the '--' argument. Other editors seem
8282 # to be fine with it (textmate [mate], light table [table]).
8383 echo " xargs -I {} tmux send-keys '$editor -- \" {}\" '; tmux send-keys 'C-m'"
8484}
8585
8686set_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 " )
8991 local key
9092 for key in $key_bindings ; do
9193 if tmux-is-at-least 2.4; then
@@ -99,8 +101,10 @@ set_copy_mode_open_bindings() {
99101}
100102
101103set_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 " ) "
104108 local key
105109 for key in $key_bindings ; do
106110 if tmux-is-at-least 2.4; then
@@ -114,13 +118,14 @@ set_copy_mode_open_editor_bindings() {
114118}
115119
116120set_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) "
118123 local engine_var
119124 local engine
120125 local key
121126
122127 for engine_var in $stored_engine_vars ; do
123- engine=" $( get_engine " $engine_var " ) "
128+ engine=" $( get_engine " $engine_var " ) " || continue
124129
125130 if tmux-is-at-least 2.4; then
126131 tmux bind-key -T copy-mode-vi " $engine_var " send-keys -X copy-pipe-and-cancel " $( generate_open_search_command " $engine " ) "
0 commit comments