git.fiddlerwoaroof.com
Browse code

feat: improve git-remote

Ed Langley authored on 19/05/2020 09:06:52
Showing 1 changed files
... ...
@@ -2,6 +2,8 @@
2 2
 autoload -U regexp-replace
3 3
 GIT_DEBUG=0
4 4
 
5
+GIT_CMD="`which -p git 2>/dev/null`"
6
+GTI_CMD="`which -p gti 2>/dev/null`"
5 7
 
6 8
 git-bump() {
7 9
   git commit -m "${SITE_PREFIX:-}(bump)" --allow-empty
... ...
@@ -130,8 +132,33 @@ alias git-hub="git-get github"
130 132
 alias git-lab="git-get gitlab"
131 133
 alias gh="git-hub"
132 134
 
133
-GIT_CMD="`which -p git 2>/dev/null`"
134
-GTI_CMD="`which -p gti 2>/dev/null`"
135
+git-remote() {
136
+  [[ "$GIT_DEBUG" == 1 ]] && set -x
137
+  base_cmd=("$GIT_CMD" remote)
138
+  opts=()
139
+  args=()
140
+  for x in "$@"; do 
141
+    if [[ "${x[1]}" == "-" ]]; then
142
+      opts=("${opts[@]}" "$x")
143
+    else
144
+      args=("${args[@]}" "$x")
145
+    fi
146
+  done
147
+  if (( $#args >= 2 )) {
148
+       a=${args[1]};
149
+       b=${args[2]};
150
+       shift 2 args;
151
+       args=("$a" "${args[@]}")
152
+       if (( $#opts > 0 )); then 
153
+         "${base_cmd[@]}" "$b" "${opts[@]}" "${args[@]}"
154
+       else 
155
+         "${base_cmd[@]}" "$b" "${args[@]}"
156
+       fi
157
+     } else {
158
+       "${base_cmd[@]}" "$@"
159
+     }
160
+  [[ "$GIT_DEBUG" == 1 ]] && set +x
161
+}
135 162
 
136 163
 if [[ ! -z "$GIT_CMD" ]]; then
137 164
   # git wrapper that mimics the functionality of git for commandlets but also
... ...
@@ -141,7 +168,7 @@ if [[ ! -z "$GIT_CMD" ]]; then
141 168
     local cmdlets
142 169
 
143 170
     possible_cmd="${${$(expand-alias "git-$1")#'}%'}"
144
-    printf "%s" "$possible_cmd" | read -A cmdlets 
171
+    printf "%s" "$possible_cmd" | read -A cmdlets
145 172
 
146 173
     if [[ "$GIT_DEBUG" != "0" ]]; then
147 174
       echo "git: looking for: \"$possible_cmd\" command: \"${cmdlets[1]}\""