Skip to content

Commit adf604f

Browse files
Luis VasconcellosBruno Sutic
authored andcommitted
Allows the configuration of any search engine
1 parent c62c014 commit adf604f

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

open.tmux

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ default_open_editor_key="C-o"
1111
open_editor_option="@open-editor"
1212
open_editor_override="@open-editor-command"
1313

14-
default_open_search_key="S"
15-
open_search_option="@open_search"
16-
open_search_override="@open_search_command"
17-
1814
command_exists() {
1915
local command="$1"
2016
type "$command" >/dev/null 2>&1
@@ -41,7 +37,9 @@ command_generator() {
4137

4238
search_command_generator() {
4339
local command_string="$1"
44-
echo "xargs -I {} tmux run-shell 'cd #{pane_current_path}; $command_string https://www.google.com/search?q=\"{}\" > /dev/null'"
40+
local engine="$2"
41+
42+
echo "xargs -I {} tmux run-shell 'cd #{pane_current_path}; $command_string $engine\"{}\" > /dev/null'"
4543
}
4644

4745
generate_open_command() {
@@ -57,9 +55,9 @@ generate_open_command() {
5755

5856
generate_open_search_command() {
5957
if is_osx; then
60-
echo "$(search_command_generator "open")"
58+
echo "$(search_command_generator "open" "$engine")"
6159
elif command_exists "xdg-open"; then
62-
echo "$(search_command_generator "xdg-open")"
60+
echo "$(search_command_generator "xdg-open" "$engine")"
6361
else
6462
# error command for Linux machines when 'xdg-open' not installed
6563
"$CURRENT_DIR/scripts/tmux_open_error_message.sh xdg-open"
@@ -97,13 +95,17 @@ set_copy_mode_open_editor_bindings() {
9795
}
9896

9997
set_copy_mode_open_search_bindings() {
100-
local search_command="$(generate_open_search_command)"
101-
local key_bindings=$(get_tmux_option "$open_search_option" "$default_open_search_key")
102-
local key
103-
for key in $key_bindings; do
104-
tmux bind-key -t vi-copy "$key" copy-pipe "$search_command"
105-
tmux bind-key -t emacs-copy "$key" copy-pipe "$search_command"
106-
done
98+
local stored_engine_vars="$(stored_engine_vars)"
99+
local engine_var
100+
local engine
101+
local key
102+
103+
for engine_var in $stored_engine_vars; do
104+
engine="$(get_engine "$engine_var")"
105+
106+
tmux bind-key -t vi-copy "$engine_var" copy-pipe "$(generate_open_search_command "$engine")"
107+
tmux bind-key -t emacs-copy "$engine_var" copy-pipe "$(generate_open_search_command "$engine")"
108+
done
107109
}
108110

109111
main() {

scripts/helpers.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ display_message() {
3333
# restores original 'display-time' value
3434
tmux set-option -gq display-time "$saved_display_time"
3535
}
36+
37+
stored_engine_vars() {
38+
tmux show-options -g | grep -i "^@open" | cut -d '-' -f2 | cut -d ' ' -f1 | xargs
39+
}
40+
41+
get_engine() {
42+
local engine_var="$1"
43+
tmux show-options -g | grep -i "^@open-$engine_var" | cut -d ' ' -f2 | xargs
44+
}

0 commit comments

Comments
 (0)