git.fiddlerwoaroof.com
Browse code

feat: fix cpwd

Edward authored on 19/05/2021 08:18:14
Showing 1 changed files
... ...
@@ -10,6 +10,29 @@ if ! [[ -d "$HOME/git*_repos" ]]; then
10 10
   mkdir -p "$HOME"/git_repos
11 11
 fi
12 12
 
13
+git-pwdurl () {
14
+  set -x
15
+  local -a parts
16
+  parts=(${(s:/:)PWD})
17
+  repo_root=${parts[(I)git_repos]}
18
+  site_idx=$((repo_root + 1))
19
+  repo_idx=$((repo_root + 2))
20
+  repo=${(j:/:)parts[$repo_idx,-1]}
21
+  site=${parts[$site_idx]}
22
+  case "$1" in
23
+    git) echo "git://$site:$repo.git"
24
+         ;;
25
+    ssh) echo git@$site:$repo.git
26
+         ;;
27
+    *) echo https://$site/$repo.git
28
+       ;;
29
+  esac
30
+}
31
+
32
+git-cpwd () {
33
+  git clone "$(git-pwdurl "$1")" .
34
+}
35
+
13 36
 git-bump() {
14 37
   git commit -m "${SITE_PREFIX:-}(bump)" --allow-empty
15 38
 }
... ...
@@ -113,22 +136,22 @@ git-gh-create() {
113 136
   local api_url=https://api.github.com/user/repos
114 137
   if (( $# == 2 )) {
115 138
        api_url="https://api.github.com/orgs/$organization_name/repos"
116
-  }
139
+     }
117 140
 
118
-  regexp-replace repo_name '[" ]' '-'
119
-  local GH_TOKEN
120
-  source "$HOME/.github-token"
121
- jq '{full_name, clone_url, ssh_url}' <( (
122
-  curl -XPOST -v \
123
-       -u "fiddlerwoaroof:$GH_TOKEN" \
124
-       "$api_url" \
125
-      -H 'Content-Type: application/json' \
126
-      --data-binary @- <<-EOF
141
+     regexp-replace repo_name '[" ]' '-'
142
+     local GH_TOKEN
143
+     source "$HOME/.github-token"
144
+     jq '{full_name, clone_url, ssh_url}' <( (
145
+                                             curl -XPOST -v \
146
+                                                  -u "fiddlerwoaroof:$GH_TOKEN" \
147
+                                                  "$api_url" \
148
+                                                  -H 'Content-Type: application/json' \
149
+                                                  --data-binary @- <<-EOF
127 150
 {
128 151
   "name": "${repo_name}"
129 152
 }
130 153
 EOF
131
-  ) )
154
+                                           ) )
132 155
 }
133 156
 
134 157
 alias git-msg=git-messages
... ...
@@ -162,7 +185,7 @@ git-remote() {
162 185
      } else {
163 186
        "${base_cmd[@]}" "$@"
164 187
      }
165
-  [[ "$GIT_DEBUG" == 1 ]] && set +x
188
+     [[ "$GIT_DEBUG" == 1 ]] && set +x
166 189
 }
167 190
 
168 191
 if [[ ! -z "$GIT_CMD" ]]; then