Blame | Last modification | View Log | RSS feed
#!/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.#GH_SSH="git@github\.com:"GH_HTTPS="https:\/\/github\.com\/"case "$1" in-[Hh]) TYPE=HTTPS ; MATCH="git@" ; FORMULA="$GH_SSH/$GH_HTTPS" ;;-[Ss]) TYPE=SSH ; MATCH="https:" ; FORMULA="$GH_HTTPS/$GH_SSH" ;;*)echo "Usage: `basename $0` -h | -s" 1>&2echo -e " \e[0;92m-h\e[0m to switch to HTTPS" 1>&2echo -e " \e[0;92m-s\e[0m to switch to SSH" 1>&2exit 1;;esacREMOTES=$(git remote -v | egrep "\t$MATCH" | gawk '{print $1 " " $2}' | sort -u | sed "s/$FORMULA/")if [[ -z $REMOTES ]]; thenecho "Nothing to do." ; exitfiecho "$REMOTES" | xargs -n2 git remote set-urlecho -n "Remotes set to $TYPE: "echo "$REMOTES" | gawk '{printf "%s ", $1}'echo