@@ -8,7 +8,7 @@ line2=${4:-""}
88
99# get remote name
1010if [[ $remote == " " ]]; then
11- branch=$( git rev-parse --abbrev-ref HEAD 2 & > /dev/null)
11+ branch=" $( git rev-parse --abbrev-ref HEAD 2> /dev/null) "
1212 remote=$( git config branch." ${branch} " .remote || echo " origin" )
1313fi
1414
@@ -31,14 +31,14 @@ elif [[ $remote_url = http* ]]; then
3131fi
3232
3333# construct urls
34- commit_hash=$( git log -n1 --format=format: " %H " " ${filename} " 2> /dev/null)
34+ commit_hash=$( git rev-parse HEAD 2> /dev/null)
3535commit_or_branch=${commit_hash:- ${branch} }
3636
3737if [[ $remote_url =~ gitlab ]]; then
3838 # construct gitlab urls
3939 # https://gitlab.com/<user_or_group>/<repo>/-/blob/<commit_or_branch>/<filename>#L<line1>-<line2>
4040 if [[ -n ${filename} ]]; then
41- url=" ${url} /-/blob/${commit_hash :- ${branch} } /${filename} "
41+ url=" ${url} /-/blob/${commit_or_branch } /${filename} "
4242 if [[ -n " ${line1} " ]]; then
4343 url=" ${url} #L${line1} "
4444 if [[ -n " ${line2} " ]]; then
@@ -50,7 +50,7 @@ elif [[ $remote_url =~ github ]]; then
5050 # construct github urls
5151 # https://github.com/<user_or_org>/<repo>/blob/<commit_or_branch>/<filename>#L<line1>-L<line2>
5252 if [[ -n " ${filename} " ]]; then
53- url=" ${url} /blob/${commit_hash :- ${branch} } /${filename} "
53+ url=" ${url} /blob/${commit_or_branch } /${filename} "
5454 if [[ -n " ${line1} " ]]; then
5555 url=" ${url} #L${line1} "
5656 if [[ -n " ${line2} " ]]; then
@@ -62,7 +62,7 @@ elif [[ $remote_url =~ bitbucket ]]; then
6262 # construct bitbucket urls
6363 # https://bitbucket.org/<user_or_org>/<repo>/src/<commit_or_branch>/<filename>#lines-<line1>:<line2>
6464 if [[ -n ${filename} ]]; then
65- url=${url} /src/${commit_hash :- ${branch} } /${filename}
65+ url=${url} /src/${commit_or_branch } /${filename}
6666 if [[ -n " ${line1} " ]]; then
6767 url=" ${url} #lines-${line1} "
6868 if [[ -n " ${line2} " ]]; then
0 commit comments