diff options
author | Georgiy Bondarenko <69736697+nehilo@users.noreply.github.com> | 2021-03-04 20:54:23 +0300 |
---|---|---|
committer | Georgiy Bondarenko <69736697+nehilo@users.noreply.github.com> | 2021-03-04 20:54:23 +0300 |
commit | e8701195e66f2d27ffe17fb514eae8173795aaf7 (patch) | |
tree | 9f519c4abf6556b9ae7190a6210d87ead1dfadde /buildroot/share/git/ghtp | |
download | kp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.tar.xz kp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.zip |
Initial commit
Diffstat (limited to 'buildroot/share/git/ghtp')
-rw-r--r-- | buildroot/share/git/ghtp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/buildroot/share/git/ghtp b/buildroot/share/git/ghtp new file mode 100644 index 0000000..14afd8a --- /dev/null +++ b/buildroot/share/git/ghtp @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# +# ghtp (GitHub Transport Protocol) +# +# Set all remotes in the current repo to HTTPS or SSH connection. +# Useful when switching environments, using public wifi, etc. +# +# Optionally, specify a particular remote to change. +# + +GH_SSH="git@github\.com:" +GH_HTTPS="https:\/\/github\.com\/" + +case "$1" in + -[Hh]) TYPE=HTTPS ; MATCH="git@" ; REPLACE="$GH_SSH/$GH_HTTPS" ;; + -[Ss]) TYPE=SSH ; MATCH="https:" ; REPLACE="$GH_HTTPS/$GH_SSH" ;; + *) + echo "Usage: `basename $0` -h | -s" 1>&2 + echo -e " \e[0;92m-h\e[0m to switch to HTTPS" 1>&2 + echo -e " \e[0;92m-s\e[0m to switch to SSH" 1>&2 + exit 1 + ;; +esac + +AWK=$(which gawk || which awk) + +# Match all or specified remotes of the other type +REGEX="\t$MATCH" ; [[ $# > 1 ]] && REGEX="^$2$REGEX" + +REMOTES=$(git remote -v | egrep "$REGEX" | "$AWK" '{print $1 " " $2}' | sort -u | sed "s/$REPLACE/") + +[[ -z $REMOTES ]] && { echo "Nothing to do." ; exit ; } + +# Update a remote for each results pair +echo "$REMOTES" | xargs -n2 git remote set-url + +echo -n "Remotes set to $TYPE: " +echo "$REMOTES" | "$AWK" '{printf "%s ", $1}' +echo |