From 299c28943077b14d42938c2ade009a1647acde14 Mon Sep 17 00:00:00 2001 From: typebrook Date: Fri, 13 Mar 2020 15:17:25 +0800 Subject: Change remote url if user configure protocol --- gist | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gist b/gist index 57a6d04..6b1776e 100755 --- a/gist +++ b/gist @@ -587,6 +587,19 @@ usage() { sed -E -n -e ' /^$/ q; 7,$ s/^# //p' "$0" } +_check_protocol() { + find $folder -maxdepth 1 -mindepth 1 -type d \ + | while read -r repo; do + cd "$repo" || exit 1 + url=$(git remote get-url origin) + if [[ $protocol == 'ssh' && $url =~ ^https ]]; then + git remote set-url origin "git@gist.github.com:$(basename `pwd`).git" + elif [[ $protocol == 'https' && $url =~ ^git ]]; then + git remote set-url origin "https://gist.github.com/$(basename `pwd`).git" + fi + done +} + _apply_config "$@" || exit 1 getConfiguredClient || exit 1 if [[ $init ]]; then _fetch_gists; exit 0; fi @@ -615,7 +628,7 @@ case "$1" in _clean_repos ;; config | c) shift - _configure "$@" ;; + _configure "$@" && (_apply_config config && _check_protocol) ;; user | U) shift _query_user "$@" ;; -- cgit v1.2.3-70-g09d2