From 61fc56a8eac54aaf8e44698b660bb146e1a59441 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Sat, 23 Dec 2023 20:14:08 -0700 Subject: [PATCH] New: git remotes ssh url script --- bin/remotes_to_ssh.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 bin/remotes_to_ssh.sh diff --git a/bin/remotes_to_ssh.sh b/bin/remotes_to_ssh.sh new file mode 100755 index 0000000..27ea5f1 --- /dev/null +++ b/bin/remotes_to_ssh.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Switch https git remote urls to ssh +git remote -v | awk ' + /https:\/\// { + split($0, a, " ") + split(a[2], b, "/") + + url = "ssh://git@"b[3]":22" + + for (i = 4; i <= length(b); i++) + url = url"/"b[i] + + if (url !~ /\.git$/) + url = url".git" + + system(sprintf("git remote set-url %s %s", a[1], url)) + printf "%s `%s` -> `%s`\n", a[1], a[2], url + } +'