Skip to content

Instantly share code, notes, and snippets.

@kyontan
Last active August 6, 2021 05:22
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 kyontan/bcb702edfc578449c0988ba2896ec1a9 to your computer and use it in GitHub Desktop.
Save kyontan/bcb702edfc578449c0988ba2896ec1a9 to your computer and use it in GitHub Desktop.
ggr: get github link

ggr: get github link

Usage

$ ls
hoge.sh
$ ggr hoge.sh
https://github.com/org/repo/blob/commithash/path_to_hoge_sh/hoge.sh
$ ggr hoge.sh 4
https://github.com/org/repo/blob/commithash/path_to_hoge_sh/hoge.sh#L4
#!/bin/sh
if [ $# -ne 1 ] && [ $# -ne 2 ]; then
echo "$0 file[:line]"
exit 1
fi
if [ $# -eq 2 ]; then
line=$2
fi
path=$(git ls-files --full-name $1)
url=https://$(git remote get-url origin | cut -d@ -f2 | tr : / | sed -e "s:.git$::")
rev=$(git rev-parse HEAD)
result="${url}/blob/${rev}/${path}"
if [ $line ]; then
result="${result}#L${line}"
fi
echo $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment