$ 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
Last active
August 6, 2021 05:22
-
-
Save kyontan/bcb702edfc578449c0988ba2896ec1a9 to your computer and use it in GitHub Desktop.
ggr: get github link
This file contains hidden or 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
#!/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