From 87acbe3874bd852c50115ff5deb9e0e7e9e0924d Mon Sep 17 00:00:00 2001 From: typebrook Date: Tue, 28 Apr 2020 11:20:01 +0800 Subject: update --- tools/swap-protocol.bash | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 tools/swap-protocol.bash (limited to 'tools/swap-protocol.bash') diff --git a/tools/swap-protocol.bash b/tools/swap-protocol.bash new file mode 100755 index 0000000..a70e7fe --- /dev/null +++ b/tools/swap-protocol.bash @@ -0,0 +1,18 @@ +#! /usr/bin/env bash + +target='' +extra='' + +git remote -v \ +| while read remote url etc; do + [[ $etc =~ push ]] && extra='--push' + if [[ -z $target || $target == https ]] && [[ $url =~ git@.*github.com ]]; then + target=${target:-https} + sed -E 's#git@(.+):(.+)#https://\1/\2#' <<<$url | xargs git remote set-url $extra $remote + elif [[ -z $target || $target == git ]] && [[ $url =~ https://.*github.com ]]; then + target=${target:-git} + sed -E 's#https://([^/]+)/(.+)#git@\1:\2#' <<<$url | xargs git remote set-url $extra $remote + fi +done + +git remote -v -- cgit v1.2.3-70-g09d2