From 47e13d36a6f5928d213f1bdbc7076f037896648b Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Wed, 25 Jan 2023 03:05:51 +0100 Subject: [PATCH] git:https-and-ssh: Support passing custom remote --- .config/zsh/autoload/git/git-https-and-ssh | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.config/zsh/autoload/git/git-https-and-ssh b/.config/zsh/autoload/git/git-https-and-ssh index 8f5fd69..779a838 100755 --- a/.config/zsh/autoload/git/git-https-and-ssh +++ b/.config/zsh/autoload/git/git-https-and-ssh @@ -1,20 +1,21 @@ #!/bin/sh #!/usr/bin/zsh -# Sets up origin so that it fetches over https but pushes over ssh. This way -# unlocking the ssh key is only needed when really necessary. +# Sets up given remote (or origin) so that it fetches over https but pushes over +# ssh. This way unlocking the ssh key is only needed when really necessary. GIT="git" -origin="$($GIT remote get-url origin)" +remote="${1:-origin}" +url="$($GIT remote get-url "$remote")" -if [ "${origin##https://}" = "$origin" ]; then - https_origin="${origin##*@}" - https_origin="https://${https_origin/://}" - $GIT remote set-url origin "$https_origin" - $GIT remote set-url --push origin "$origin" +if [ "${url##https://}" = "$url" ]; then + https_url="${url##*@}" + https_url="https://${https_url/://}" + $GIT remote set-url "$remote" "$https_url" + $GIT remote set-url --push "$remote" "$url" else - ssh_origin="${origin##https://}" - ssh_origin="git@${ssh_origin/\//:}" - $GIT remote set-url --push origin "$ssh_origin" + ssh_url="${url##https://}" + ssh_url="git@${ssh_url/\//:}" + $GIT remote set-url --push "$remote" "$ssh_url" fi