Created
February 9, 2020 22:42
-
-
Save yyolk/04341e58b1a5d8d60e6166a22fcae94d to your computer and use it in GitHub Desktop.
a bash cli for googling things from the cli using, can be easily ported elsewhere source and then `goog something i'm looking for`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# modified from https://stackoverflow.com/a/10660730 | |
rawurlencode() { | |
local string="${1}" | |
local strlen=${#string} | |
local encoded="" | |
local pos c o | |
for (( pos=0 ; pos<strlen ; pos++ )); do | |
c=${string:$pos:1} | |
case "$c" in | |
" " ) o="+" ;; | |
[-_.~a-zA-Z0-9] ) o="${c}" ;; | |
* ) printf -v o '%%%02x' "'$c" | |
esac | |
encoded+="${o}" | |
done | |
echo "${encoded}" # You can either set a return variable (FASTER) | |
#REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p | |
} | |
goog() { | |
xdg-open "https://google.com/search?q=$( rawurlencode "$*" )" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment