ソースを参照

Allow 'ghtp' to set a specific remote

Scott Lahteine 3年前
コミット
d10b11ad9f
1個のファイルの変更10行の追加6行の削除
  1. 10
    6
      buildroot/share/git/ghtp

+ 10
- 6
buildroot/share/git/ghtp ファイルの表示

5
 # Set all remotes in the current repo to HTTPS or SSH connection.
5
 # Set all remotes in the current repo to HTTPS or SSH connection.
6
 # Useful when switching environments, using public wifi, etc.
6
 # Useful when switching environments, using public wifi, etc.
7
 #
7
 #
8
+# Optionally, specify a particular remote to change.
9
+#
8
 
10
 
9
 GH_SSH="git@github\.com:"
11
 GH_SSH="git@github\.com:"
10
 GH_HTTPS="https:\/\/github\.com\/"
12
 GH_HTTPS="https:\/\/github\.com\/"
11
 
13
 
12
 case "$1" in
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
     echo "Usage: `basename $0` -h | -s" 1>&2
18
     echo "Usage: `basename $0` -h | -s" 1>&2
17
     echo -e " \e[0;92m-h\e[0m to switch to HTTPS" 1>&2
19
     echo -e " \e[0;92m-h\e[0m to switch to HTTPS" 1>&2
22
 
24
 
23
 AWK=$(which gawk || which awk)
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
 echo "$REMOTES" | xargs -n2 git remote set-url
35
 echo "$REMOTES" | xargs -n2 git remote set-url
32
 
36
 
33
 echo -n "Remotes set to $TYPE: "
37
 echo -n "Remotes set to $TYPE: "

読み込み中…
キャンセル
保存