From 75992172bfecf78bf78b2a6a6ab4f6361a2df33a Mon Sep 17 00:00:00 2001 From: typebrook Date: Tue, 28 Apr 2020 11:11:19 +0800 Subject: update --- gitconfig | 10 +--------- tools/swap-protocol.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) create mode 100755 tools/swap-protocol.sh diff --git a/gitconfig b/gitconfig index c0af895..5418f98 100644 --- a/gitconfig +++ b/gitconfig @@ -9,15 +9,7 @@ git stash apply stash@{1} && \ git stash show -p | git apply -R && \ git stash drop stash@{1} -# swapProtoccol = !bash "\ -# remote={$1}\ -# url='git@github.com:typberook/settings.git'\ -# if [ $url =~ ^git ]; then\ -# new_url=$(echo $url | sed 's#git@#https://#; s#:#/#');\ -# else\ -# new_url=$url;\ -# fi;\ -# git remote set-url $remote $new_url" + swapprotocol = !swap-protocol.sh [core] pager = tig 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