Skip to content

Instantly share code, notes, and snippets.

@cdzombak
Last active February 2, 2021 18:15
Show Gist options
  • Save cdzombak/d4664d71a50a860a598beac7e483d8c2 to your computer and use it in GitHub Desktop.
Save cdzombak/d4664d71a50a860a598beac7e483d8c2 to your computer and use it in GitHub Desktop.
Shell script adding `git google *` to git subcommands. Put this file, named `git-google`, somewhere in your $PATH, and be sure to make this file executable. Then, type "git google commit," for example, to open a Google search for "git commit tutorial." Hacky AF, but it does generally work.
#!/usr/bin/env bash
set -e
urlencode() {
# from https://gist.github.com/cdown/1163649
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:$i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf '%s' "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
LC_COLLATE=$old_lc_collate
}
Q=$(urlencode "git $(echo "$@") tutorial")
open "https://google.com/search?q=$Q"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment