Skip to content

Commit 94cb758

Browse files
Luis VasconcellosBruno Sutic
authored andcommitted
Adds the google search feature
1 parent dcbdac0 commit 94cb758

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

open.tmux

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ 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+
1418
command_exists() {
1519
local command="$1"
1620
type "$command" >/dev/null 2>&1
@@ -35,6 +39,11 @@ command_generator() {
3539
echo "xargs -I {} tmux run-shell 'cd #{pane_current_path}; $command_string \"{}\" > /dev/null'"
3640
}
3741

42+
search_command_generator() {
43+
local command_string="$1"
44+
echo "xargs -I {} tmux run-shell 'cd ~/Development/Tmux/tmux-open; $command_string https://www.google.com.br/search?q=\"{}\" > /dev/null'"
45+
}
46+
3847
generate_open_command() {
3948
if is_osx; then
4049
echo "$(command_generator "open")"
@@ -46,6 +55,17 @@ generate_open_command() {
4655
fi
4756
}
4857

58+
generate_open_search_command() {
59+
if is_osx; then
60+
echo "$(search_command_generator "open")"
61+
elif command_exists "xdg-open"; then
62+
echo "$(search_command_generator "xdg-open")"
63+
else
64+
# error command for Linux machines when 'xdg-open' not installed
65+
"$CURRENT_DIR/scripts/tmux_open_error_message.sh xdg-open"
66+
fi
67+
}
68+
4969
# 1. write a command to the terminal, example: 'vim -- some_file.txt'
5070
# 2. invoke the command by pressing enter/C-m
5171
generate_editor_command() {
@@ -76,8 +96,20 @@ set_copy_mode_open_editor_bindings() {
7696
done
7797
}
7898

99+
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
107+
}
108+
79109
main() {
80110
set_copy_mode_open_bindings
81111
set_copy_mode_open_editor_bindings
112+
set_copy_mode_open_search_bindings
82113
}
114+
83115
main

0 commit comments

Comments
 (0)