From a55af3436450e1d1e86e7138c8ea0e86b9fbcd59 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Sun, 22 Jan 2023 11:29:09 -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 + } +'