From 87acbe3874bd852c50115ff5deb9e0e7e9e0924d Mon Sep 17 00:00:00 2001 From: typebrook Date: Tue, 28 Apr 2020 11:20:01 +0800 Subject: update --- gitconfig | 2 +- tools/swap-protocol.bash | 18 ++++++++++++++++++ tools/swap-protocol.sh | 16 ---------------- 3 files changed, 19 insertions(+), 17 deletions(-) create mode 100755 tools/swap-protocol.bash delete mode 100755 tools/swap-protocol.sh diff --git a/gitconfig b/gitconfig index 5418f98..cd29063 100644 --- a/gitconfig +++ b/gitconfig @@ -9,7 +9,7 @@ git stash apply stash@{1} && \ git stash show -p | git apply -R && \ git stash drop stash@{1} - swapprotocol = !swap-protocol.sh + swapprotocol = !swap-protocol.bash [core] pager = tig 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 diff --git a/tools/swap-protocol.sh b/tools/swap-protocol.sh deleted file mode 100755 index 03594f8..0000000 --- a/tools/swap-protocol.sh +++ /dev/null @@ -1,16 +0,0 @@ -#! /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