From 75992172bfecf78bf78b2a6a6ab4f6361a2df33a Mon Sep 17 00:00:00 2001 From: typebrook Date: Tue, 28 Apr 2020 11:11:19 +0800 Subject: update --- tools/swap-protocol.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 tools/swap-protocol.sh (limited to 'tools/swap-protocol.sh') diff --git a/tools/swap-protocol.sh b/tools/swap-protocol.sh new file mode 100755 index 0000000..03594f8 --- /dev/null +++ b/tools/swap-protocol.sh @@ -0,0 +1,16 @@ +#! /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 -- cgit v1.2.3-70-g09d2