From 4c868736503d48aa96081db8c61fd02e3d94a803 Mon Sep 17 00:00:00 2001 From: Liam Galvin Date: Wed, 28 Nov 2018 20:01:54 +0000 Subject: [PATCH 1/2] Made search engine configurable --- README.md | 3 ++- config/actions.go | 2 +- config/config.go | 1 + config/defaults.go | 1 + gui/actions.go | 9 +++++---- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 93b0f89..5f40beb 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ As long as you have your `GOBIN` environment variable set up properly (and in `P | Select line | triple click | | Copy | `ctrl + shift + c` (Mac: `super + c`) | | Paste | `ctrl + shift + v` (Mac: `super + v`) | -| Google selected text | `ctrl + shift + g` (Mac: `super + g`) | +| Search online for selected text | `ctrl + shift + g` (Mac: `super + g`) | | Toggle debug display | `ctrl + shift + d` (Mac: `super + d`) | | Toggle slomo | `ctrl + shift + ;` (Mac: `super + ;`) | | Report bug in aminal | `ctrl + shift + r` (Mac: `super + r`) | @@ -90,6 +90,7 @@ You can ignore the config and use defaults by specifying `--ignore-config` as a debug = false # Enable debug logging to stdout. Defaults to false. slomo = false # Enable slow motion output mode, useful for debugging shells/terminal GUI apps etc. Defaults to false. shell = "/bin/bash" # The shell to run for the terminal session. Defaults to the users shell. +search_url = "https://www.google.com/search?q=$QUERY" # The search engine to use for the "search selected text" action. Defaults to google. Set this to your own search url using $QUERY as the keywords to replcae when searching. [colours] cursor = "#e8dfd6" diff --git a/config/actions.go b/config/actions.go index b891b1f..21bfe0c 100644 --- a/config/actions.go +++ b/config/actions.go @@ -5,7 +5,7 @@ type UserAction string const ( ActionCopy UserAction = "copy" ActionPaste UserAction = "paste" - ActionGoogle UserAction = "google" + ActionSearch UserAction = "search" ActionReportBug UserAction = "report" ActionToggleDebug UserAction = "debug" ActionToggleSlomo UserAction = "slomo" diff --git a/config/config.go b/config/config.go index 15b2dc7..28024be 100644 --- a/config/config.go +++ b/config/config.go @@ -12,6 +12,7 @@ type Config struct { ColourScheme ColourScheme `toml:"colours"` Shell string `toml:"shell"` KeyMapping KeyMappingConfig `toml:"keys"` + SearchURL string `toml:"search_url"` } type KeyMappingConfig map[string]string diff --git a/config/defaults.go b/config/defaults.go index 2282608..64041a3 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -27,6 +27,7 @@ var DefaultConfig = Config{ Selection: strToColourNoErr("#333366"), }, KeyMapping: KeyMappingConfig(map[string]string{}), + SearchURL: "https://www.google.com/search?q=$QUERY", } func init() { diff --git a/gui/actions.go b/gui/actions.go index 3539061..d250f9a 100644 --- a/gui/actions.go +++ b/gui/actions.go @@ -3,6 +3,7 @@ package gui import ( "fmt" "net/url" + "strings" "github.com/liamg/aminal/config" ) @@ -11,7 +12,7 @@ var actionMap = map[config.UserAction]func(gui *GUI){ config.ActionCopy: actionCopy, config.ActionPaste: actionPaste, config.ActionToggleDebug: actionToggleDebug, - config.ActionGoogle: actionGoogleSelection, + config.ActionSearch: actionSearchSelection, config.ActionToggleSlomo: actionToggleSlomo, config.ActionReportBug: actionReportBug, } @@ -31,10 +32,10 @@ func actionToggleDebug(gui *GUI) { gui.terminal.SetDirty() } -func actionGoogleSelection(gui *GUI) { +func actionSearchSelection(gui *GUI) { keywords := gui.terminal.ActiveBuffer().GetSelectedText() - if keywords != "" { - gui.launchTarget(fmt.Sprintf("https://www.google.com/search?q=%s", url.QueryEscape(keywords))) + if keywords != "" && gui.config.SearchURL != "" && strings.Contains(gui.config.SearchURL, "$QUERY") { + gui.launchTarget(fmt.Sprintf(strings.Replace(gui.config.SearchURL, "$QUERY", "%s", 1), url.QueryEscape(keywords))) } } From eb4deb86611147ed3ddd513696305e15d5f9d754 Mon Sep 17 00:00:00 2001 From: Liam Galvin Date: Wed, 28 Nov 2018 20:12:07 +0000 Subject: [PATCH 2/2] missed renaming google action --- config/defaults.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/defaults.go b/config/defaults.go index 64041a3..9ff3544 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -33,7 +33,7 @@ var DefaultConfig = Config{ func init() { DefaultConfig.KeyMapping[string(ActionCopy)] = addMod("c") DefaultConfig.KeyMapping[string(ActionPaste)] = addMod("v") - DefaultConfig.KeyMapping[string(ActionGoogle)] = addMod("g") + DefaultConfig.KeyMapping[string(ActionSearch)] = addMod("g") DefaultConfig.KeyMapping[string(ActionToggleDebug)] = addMod("d") DefaultConfig.KeyMapping[string(ActionToggleSlomo)] = addMod(";") DefaultConfig.KeyMapping[string(ActionReportBug)] = addMod("r")