aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-04-28 11:11:19 +0800
committertypebrook <typebrook@gmail.com>2020-04-28 11:11:19 +0800
commit75992172bfecf78bf78b2a6a6ab4f6361a2df33a (patch)
tree0d18896d030aac89b0e4cb36d2f94e6129a1e81a
parent9d6b7201c9b3277e6840ef873dba651d5c3e9011 (diff)
update
-rw-r--r--gitconfig10
-rwxr-xr-xtools/swap-protocol.sh16
2 files changed, 17 insertions, 9 deletions
diff --git a/gitconfig b/gitconfig
index c0af895..5418f98 100644
--- a/gitconfig
+++ b/gitconfig
@@ -9,15 +9,7 @@
9 git stash apply stash@{1} && \ 9 git stash apply stash@{1} && \
10 git stash show -p | git apply -R && \ 10 git stash show -p | git apply -R && \
11 git stash drop stash@{1} 11 git stash drop stash@{1}
12# swapProtoccol = !bash "\ 12 swapprotocol = !swap-protocol.sh
13# remote={$1}\
14# url='git@github.com:typberook/settings.git'\
15# if [ $url =~ ^git ]; then\
16# new_url=$(echo $url | sed 's#git@#https://#; s#:#/#');\
17# else\
18# new_url=$url;\
19# fi;\
20# git remote set-url $remote $new_url"
21 13
22[core] 14[core]
23 pager = tig 15 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 @@
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