File tree Expand file tree Collapse file tree 1 file changed +29
-11
lines changed Expand file tree Collapse file tree 1 file changed +29
-11
lines changed Original file line number Diff line number Diff line change 22# -*- coding: utf-8 -*-
33#
44function core::internal::git::get_module_path {
5+ local basename
56 if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1 ; then
6- echo " unknown/unknown/$( basename " $( pwd) " ) "
7- return
7+ basename=" $( basename " $( pwd) " ) "
8+ core::internal::message::error " not git repository → ${basename} "
9+ return 0
810 fi
911
1012 local remote_url
1113 remote_url=" $( git config --get remote.origin.url) "
1214
13- if [[ " $remote_url " =~ ^git@ ([^:]+):(.+)\. git$ ]]; then
14- # [email protected] :hadenlabs/zsh-core.git → github.com/hadenlabs/zsh-core 15- echo " ${BASH_REMATCH[1]} /${BASH_REMATCH[2]} "
16- elif [[ " $remote_url " =~ ^https? ://([^/]+)/(.+)\. git$ ]]; then
17- # https://github.com/hadenlabs/zsh-core.git → github.com/hadenlabs/zsh-core
18- echo " ${BASH_REMATCH[1]} /${BASH_REMATCH[2]} "
19- else
20- echo " unknown/unknown/$( basename " $( pwd) " ) "
21- fi
15+ echo " $remote_url " | awk '
16+ {
17+ if ($0 ~ /^git@/) {
18+ sub(/^git@/, "", $0)
19+ split($0, a, ":")
20+ host = a[1]
21+ path = a[2]
22+ }
23+ else if ($0 ~ /^https?:\/\//) {
24+ sub(/^https?:\/\//, "", $0)
25+ split($0, a, "/")
26+ host = a[1]
27+ path = substr($0, length(host) + 2)
28+ }
29+ else {
30+ print "unknown/unknown/" ENVIRON["PWD"]
31+ exit
32+ }
33+
34+ if (path ~ /\.git$/) {
35+ sub(/\.git$/, "", path)
36+ }
37+
38+ print host "/" path
39+ }'
2240}
You can’t perform that action at this time.
0 commit comments