diff --git a/prompt b/prompt index 876f189..5bb764b 100755 --- a/prompt +++ b/prompt @@ -11,7 +11,7 @@ launch() { Music Browser Email - Processes" | tr '\t' | + Processes" | tr -d '\t' | dmenu -i -p "Launcher") case $app in @@ -35,6 +35,8 @@ action() { Toggle Music Command Command to clipboard + Search github + Search ddg Select VPN Disable VPN Enable VPN @@ -51,6 +53,8 @@ case $action in 'Rebind Keys') setup-xbindkeys;; 'Disable Bar') tmux set -g status off;; 'Enable Bar') tmux set -g status on;; + 'Search github') github;; + 'Search ddg') ddg;; 'Command') cmd;; 'Command to clipboard') cmd_clip;; esac @@ -80,7 +84,7 @@ both" | fi } -ddg() { +search_type() { search_string="$(printf "New window\nBookmarks\nHistory" | dmenu -p "ddg")" search_mode='tab' @@ -88,9 +92,28 @@ ddg() { 'New window') search_mode='window'; search_string=$(printf '' | dmenu -p 'new ddg');; 'Bookmarks');; 'History') ;; - *) printf "Invalid argument";; + # *) printf "Invalid argument";; esac + printf "$search_string|$search_mode" +} +brave_search() { + search_prefix="$1" + search_info="$(search_type)" + 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";; + esac +} + +rawurlencode() { + #Takes the first argument and encodes it + search_string="$1" string_length=$(expr length "$search_string") char=''; new_string=''; @@ -98,23 +121,22 @@ ddg() { while [ $i -le $string_length ] do char=$(expr substr "$search_string" $i 1) - new_string="$new_string$(rawurlencode "$char")" - # printf "this is newstring %s\n" "$new_string" + # new_string="$new_string$(rawurlencode "$char")" + case "$char" in + [-_.~a-zA-Z0-9] ) new_string="$new_string$char";; + * ) new_string="$new_string%$(printf '%%%02x' "'$char")";; + esac i=$(expr $i + 1) done - search="https://duckduckgo.com/?q=$new_string" + printf "$new_string" +} - case "$search_mode" in - tab) brave-browser "$search";; - window) brave-browser --new-window "$search";; - esac +ddg() { + brave_search "https://duckduckgo.com/?q=" } -rawurlencode() { - case "$1" in - [-_.~a-zA-Z0-9] ) result=$1; printf $result;; - * ) result=$(printf '%%%02x' "'$1"); printf %$result;; - esac +github() { + brave_search "https://github.com/search?q=" } cmd() { @@ -133,6 +155,7 @@ case $1 in action) action;; cmd) action;; cmd_clip) cmd_clip;; - ddg) ddg;; + ddg) brave_search "https://duckduckgo.com/?q=";; + github) brave_search "https://github.com/search?q=";; *) printf "Invalid argument";; esac