aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/swap-protocol.bash
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-04-28 11:20:01 +0800
committertypebrook <typebrook@gmail.com>2020-04-28 11:20:01 +0800
commit87acbe3874bd852c50115ff5deb9e0e7e9e0924d (patch)
tree4c71c9ca6cc4ea461db07f06f312ebd1173518b9 /tools/swap-protocol.bash
parent75992172bfecf78bf78b2a6a6ab4f6361a2df33a (diff)
update
Diffstat (limited to 'tools/swap-protocol.bash')
-rwxr-xr-xtools/swap-protocol.bash18
1 files changed, 18 insertions, 0 deletions
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 @@
1#! /usr/bin/env bash
2
3target=''
4extra=''
5
6git remote -v \
7| while read remote url etc; do
8 [[ $etc =~ push ]] && extra='--push'
9 if [[ -z $target || $target == https ]] && [[ $url =~ git@.*github.com ]]; then
10 target=${target:-https}
11 sed -E 's#git@(.+):(.+)#https://\1/\2#' <<<$url | xargs git remote set-url $extra $remote
12 elif [[ -z $target || $target == git ]] && [[ $url =~ https://.*github.com ]]; then
13 target=${target:-git}
14 sed -E 's#https://([^/]+)/(.+)#git@\1:\2#' <<<$url | xargs git remote set-url $extra $remote
15 fi
16done
17
18git remote -v