Skip to content

Instantly share code, notes, and snippets.

@huynp1999
Last active October 5, 2022 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huynp1999/04b8cdb08da8f4c1075c21cae258d1cb to your computer and use it in GitHub Desktop.
Save huynp1999/04b8cdb08da8f4c1075c21cae258d1cb to your computer and use it in GitHub Desktop.
Enable google search option for gnome terminal 3.44
diff --git a/src/terminal-util.cc b/src/terminal-util.cc
index b430efca..8b882ad9 100644
--- a/src/terminal-util.cc
+++ b/src/terminal-util.cc
@@ -113,7 +113,7 @@ terminal_util_show_error_dialog (GtkWindow *transient_parent,
}
}
-static gboolean
+gboolean
open_url (GtkWindow *parent,
const char *uri,
guint32 user_time,
diff --git a/src/terminal-util.hh b/src/terminal-util.hh
index d980725e..91e4a2ff 100644
--- a/src/terminal-util.hh
+++ b/src/terminal-util.hh
@@ -109,6 +109,12 @@ char *terminal_util_find_program_in_path (const char *path,
gboolean terminal_util_check_envv(char const* const* strv);
+gboolean
+open_url (GtkWindow *parent,
+ const char *uri,
+ guint32 user_time,
+ GError **error);
+
G_END_DECLS
#endif /* TERMINAL_UTIL_H */
diff --git a/src/terminal-window.cc b/src/terminal-window.cc
index 78fcbc1a..673dca98 100644
--- a/src/terminal-window.cc
+++ b/src/terminal-window.cc
@@ -670,6 +670,29 @@ action_copy_cb (GSimpleAction *action,
vte_terminal_copy_clipboard_format (VTE_TERMINAL (priv->active_screen), format);
}
+static void
+action_google_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ TerminalWindow *window = (TerminalWindow*)user_data;
+ TerminalWindowPrivate *priv = window->priv;
+ const char *format_str;
+ VteFormat format;
+ gchar *url;
+ GtkClipboard *clipboard;
+
+ if (priv->active_screen == NULL)
+ return;
+
+ g_assert_nonnull (parameter);
+ g_variant_get (parameter, "&s", &format_str);
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (window), GDK_SELECTION_PRIMARY);
+ url = g_strdup_printf ("http://www.google.com/search?ie=UTF-8&q=%s", gtk_clipboard_wait_for_text(clipboard));
+ open_url (GTK_WINDOW (window), url, gtk_get_current_event_time (), NULL);
+ g_free(url);
+}
+
/* Clipboard helpers */
typedef struct {
@@ -1774,6 +1797,7 @@ screen_show_popup_menu_cb (TerminalScreen *screen,
g_menu_append (section4, _("_Copy"), "win.copy::text");
g_menu_append (section4, _("Copy as _HTML"), "win.copy::html");
g_menu_append (section4, _("_Paste"), "win.paste-text");
+ g_menu_append (section4, _("Search on Google"), "win.search-google::text");
if (g_action_get_enabled (G_ACTION (lookup_action (window, "paste-uris"))))
g_menu_append (section4, _("Paste as _Filenames"), "win.paste-uris");
@@ -2100,6 +2124,7 @@ terminal_window_init (TerminalWindow *window)
{ "paste-uris", action_paste_uris_cb, nullptr, nullptr, nullptr },
{ "reset", action_reset_cb, "b", nullptr, nullptr },
{ "select-all", action_select_all_cb, nullptr, nullptr, nullptr },
+ { "search-google", action_google_cb, "s", NULL, NULL },
{ "size-to", action_size_to_cb, "(uu)", nullptr, nullptr },
{ "tab-detach", action_tab_detach_cb, nullptr, nullptr, nullptr },
{ "tab-move-left", action_tab_move_left_cb, nullptr, nullptr, nullptr },
@huynp1999
Copy link
Author

huynp1999 commented Oct 4, 2022

Steps to apply patch:

apt-get build-dep gnome-terminal
cd /usr/local/src
apt-get -b source gnome-terminal
cd gnome-terminal-3.44.0
wget https://gist.githubusercontent.com/huynp1999/24a8fd872ecbd1736cf80862984f4c47/raw/0a8ff2ea7d481f015b45bc6cea69480ced44cdcc/gnome_terminal_with_google.patch
cat gnome_terminal_with_google.patch | patch -p 1
meson _build -Dsearch_provider=false
ninja -C _build
ninja -C _build install

Kill all current gnome-terminal to use new patched version.

Or

/usr/local/bin/gnome-terminal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment