瀏覽代碼

Allow 'ghtp' to set a specific remote

Scott Lahteine 4 年之前
父節點
當前提交
d10b11ad9f
共有 1 個檔案被更改,包括 10 行新增6 行删除
  1. 10
    6
      buildroot/share/git/ghtp

+ 10
- 6
buildroot/share/git/ghtp 查看文件

@@ -5,13 +5,15 @@
5 5
 # Set all remotes in the current repo to HTTPS or SSH connection.
6 6
 # Useful when switching environments, using public wifi, etc.
7 7
 #
8
+# Optionally, specify a particular remote to change.
9
+#
8 10
 
9 11
 GH_SSH="git@github\.com:"
10 12
 GH_HTTPS="https:\/\/github\.com\/"
11 13
 
12 14
 case "$1" in
13
-  -[Hh]) TYPE=HTTPS ; MATCH="git@" ; FORMULA="$GH_SSH/$GH_HTTPS" ;;
14
-  -[Ss]) TYPE=SSH ; MATCH="https:" ; FORMULA="$GH_HTTPS/$GH_SSH" ;;
15
+  -[Hh]) TYPE=HTTPS ; MATCH="git@" ; REPLACE="$GH_SSH/$GH_HTTPS" ;;
16
+  -[Ss]) TYPE=SSH ; MATCH="https:" ; REPLACE="$GH_HTTPS/$GH_SSH" ;;
15 17
   *)
16 18
     echo "Usage: `basename $0` -h | -s" 1>&2
17 19
     echo -e " \e[0;92m-h\e[0m to switch to HTTPS" 1>&2
@@ -22,12 +24,14 @@ esac
22 24
 
23 25
 AWK=$(which gawk || which awk)
24 26
 
25
-REMOTES=$(git remote -v | egrep "\t$MATCH" | "$AWK" '{print $1 " " $2}' | sort -u | sed  "s/$FORMULA/")
27
+# Match all or specified remotes of the other type
28
+REGEX="\t$MATCH" ; [[ $# > 1 ]] && REGEX="^$2$REGEX"
29
+
30
+REMOTES=$(git remote -v | egrep "$REGEX" | "$AWK" '{print $1 " " $2}' | sort -u | sed  "s/$REPLACE/")
26 31
 
27
-if [[ -z $REMOTES ]]; then
28
-  echo "Nothing to do." ; exit
29
-fi
32
+[[ -z $REMOTES ]] && { echo "Nothing to do." ; exit ; }
30 33
 
34
+# Update a remote for each results pair
31 35
 echo "$REMOTES" | xargs -n2 git remote set-url
32 36
 
33 37
 echo -n "Remotes set to $TYPE: "

Loading…
取消
儲存