@@ -19,6 +19,7 @@ git open [remote] [branch]
19
19
c,commit! open current commit
20
20
i,issue! open issues page
21
21
s,suffix= append this suffix
22
+ f,file= append this file
22
23
p,print! just print the url
23
24
"
24
25
@@ -32,12 +33,14 @@ is_issue=0
32
33
protocol=" https"
33
34
print_only=0
34
35
suffix_flag=" "
36
+ file_flag=" "
35
37
36
38
while test $# ! = 0; do
37
39
case " $1 " in
38
40
--commit) is_commit=1;;
39
41
--issue) is_issue=1;;
40
42
--suffix=* ) suffix_flag=" $1 " ;;
43
+ --file=* ) file_flag=" $1 " ;;
41
44
--print) print_only=1;;
42
45
--) shift ; break ;;
43
46
esac
@@ -49,6 +52,10 @@ IFS='=' read -ra suffix_flag <<< "$suffix_flag"
49
52
function join_by { local IFS=" $1 " ; shift ; echo " $* " ; }
50
53
suffix=$( join_by " =" " ${suffix_flag[@]: 1} " )
51
54
55
+ # parse file from file=value
56
+ IFS=' =' read -ra file_flag <<< " $file_flag"
57
+ file=$( join_by " =" " ${file_flag[@]: 1} " )
58
+
52
59
# are we in a git repo?
53
60
if ! git rev-parse --is-inside-work-tree & > /dev/null; then
54
61
echo " Not a git repository." 1>&2
@@ -246,11 +253,20 @@ openurl="$protocol://$domain/$urlpath"
246
253
if (( is_commit )) ; then
247
254
sha=$( git rev-parse HEAD)
248
255
openurl=" $openurl /commit/$sha "
249
- elif [[ $remote_ref != " master" ]]; then
256
+ elif [[ $remote_ref != " master" || " $file " ]]; then
250
257
# simplify URL for master
251
258
openurl=" $openurl$providerBranchRef "
252
259
fi
253
260
261
+ if [ " $file " ]; then
262
+ absfile=$( git ls-tree --full-name --name-only $branch $file )
263
+ if [[ -z " $absfile " ]]; then
264
+ echo " File $file is not in repository" 1>&2
265
+ exit 1
266
+ fi
267
+ openurl=" $openurl /$absfile "
268
+ fi
269
+
254
270
if [ " $suffix " ]; then
255
271
openurl=" $openurl /$suffix "
256
272
fi
0 commit comments