From 9c8301b457e574c0e74bc8b40fb4c6e8075573d8 Mon Sep 17 00:00:00 2001
From: = <=>
Date: Mon, 21 Dec 2020 19:04:40 -0500
Subject: [PATCH] Add godoc and man pages functions

---
 README.md |  2 +-
 prompt    | 48 +++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/README.md b/README.md
index 1cee5d7..dfae7bb 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 
 # Macros
-This is a collection of commands I use to make managing files and processes easier.
+This is a collection of scripts I use to make managing files and processes easier.
 Use it to automagically select and run terminal applications, send signals to daemons, execute arbitrary commands, search the web, grab passwords from a password manager, and more.
 
 ## Prompt
diff --git a/prompt b/prompt
index 5bb764b..21d8eb2 100755
--- a/prompt
+++ b/prompt
@@ -1,5 +1,8 @@
 #!/bin/sh
 
+browser_cmd="brave-browser"
+browser_new_cmd="brave-browser --new-window"
+
 launch() {
 	app=$(printf "Notes
 	Files
@@ -23,8 +26,8 @@ case $app in
 	LBRY) lbry;;
 	Chat) element-desktop;;
 	Music) st -e ncmpcpp;;
-	Browser) brave-browser;;
-	Email) brave-browser mail.protonmail.com/login;;
+	Browser) $browser_cmd;;
+	Email) $browser_cmd mail.protonmail.com/login;;
 	Processes) st -e htop;;
 esac
 }
@@ -37,6 +40,7 @@ action() {
 	Command to clipboard
 	Search github
 	Search ddg
+	Search godoc
 	Select VPN
 	Disable VPN
 	Enable VPN
@@ -54,6 +58,7 @@ case $action in
 	'Disable Bar') tmux set -g status off;;
 	'Enable Bar') tmux set -g status on;;
 	'Search github') github;;
+	'Search godoc') godoc;;
 	'Search ddg') ddg;;
 	'Command') cmd;;
 	'Command to clipboard') cmd_clip;;
@@ -85,11 +90,11 @@ both" |
 }
 
 search_type() {
-	search_string="$(printf "New window\nBookmarks\nHistory" | dmenu -p "ddg")"
+	search_string="$(printf "New window\nBookmarks\nHistory" | dmenu -p "$1")"
 	search_mode='tab'
 
 	case "$search_string" in
-		'New window') search_mode='window'; search_string=$(printf '' | dmenu -p 'new ddg');;
+		'New window') search_mode='window'; search_string=$(printf '' | dmenu -p "new $1");;
 		'Bookmarks');;
 		'History') ;;
 		# *) printf "Invalid argument";;
@@ -99,15 +104,15 @@ search_type() {
 
 brave_search() {
 	search_prefix="$1"
-	search_info="$(search_type)"
+	search_info="$(search_type "$2")"
 	search_string=$(printf "$search_info" | cut -d'|' -f1)
 	search_mode=$(printf "$search_info" | cut -d'|' -f2)
 	if [ -z "$search_string" ]; then exit; fi
 	new_string=$(rawurlencode "$search_string")
 	search="$search_prefix$new_string"
 	case "$search_mode" in 
-		tab) brave-browser "$search";;
-		window) brave-browser --new-window "$search";;
+		tab) $browser_cmd "$search";;
+		window) $browser_new_cmd "$search";;
 	esac
 }
 
@@ -132,11 +137,29 @@ rawurlencode() {
 }
 
 ddg() {
-	brave_search "https://duckduckgo.com/?q="
+	brave_search "https://duckduckgo.com/?q=" "ddg"
 }
 
 github() {
-	brave_search "https://github.com/search?q="
+	brave_search "https://github.com/search?q=" "github"
+}
+
+godoc() {
+	brave_search "https://golang.org/pkg/" "godoc"
+}
+
+manual() {
+	search=$(printf '' | dmenu -p 'manual')
+	result=$(man "$search")
+	printf "$result" | zathura -
+	# notify-send -u low -t 0 "Manual" "$result"
+}
+
+goinfo() {
+	#Maybe this can also show recent searches
+	search=$(printf '' | dmenu -p 'goinfo')
+	result=$(go doc "$search")
+	notify-send -u low -t -1 "Go documentation" "$result"
 }
 
 cmd() {
@@ -155,7 +178,10 @@ case $1 in
 	action) action;;
 	cmd) action;;
 	cmd_clip) cmd_clip;;
-	ddg) brave_search "https://duckduckgo.com/?q=";;
-	github) brave_search "https://github.com/search?q=";;
+	ddg) ddg;;
+	github) github;;
+	godoc) godoc;;
+	goinfo) goinfo;;
+	manual) manual;;
 	*) printf "Invalid argument";;
 esac