aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/swap-protocol.sh
blob: 03594f81f3510b23eb7e71f1fcdf6754c3fd480a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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