Skip to content

Instantly share code, notes, and snippets.

@yyolk
Created February 9, 2020 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yyolk/04341e58b1a5d8d60e6166a22fcae94d to your computer and use it in GitHub Desktop.
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`
# 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