Made search engine configurable

This commit is contained in:
Liam Galvin 2018-11-28 20:01:54 +00:00
parent 24a7c629e1
commit 4c86873650
5 changed files with 10 additions and 6 deletions

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -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() {

View File

@ -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)))
}
}