From 19fc37299a337cb4a3ac9c7865a07c4a74661f5e Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Wed, 30 Oct 2024 09:56:42 +0100 Subject: [PATCH] git:https-and-ssh: Make POSIX-shell compliant Don't know why this had two shebangs and how I never noticed. Apparently I only launched the script through the autoloaded function in zsh. --- .config/zsh/autoload/git/git-https-and-ssh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.config/zsh/autoload/git/git-https-and-ssh b/.config/zsh/autoload/git/git-https-and-ssh index 779a838..e16b94c 100755 --- a/.config/zsh/autoload/git/git-https-and-ssh +++ b/.config/zsh/autoload/git/git-https-and-ssh @@ -1,5 +1,4 @@ #!/bin/sh -#!/usr/bin/zsh # 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. @@ -10,12 +9,12 @@ remote="${1:-origin}" url="$($GIT remote get-url "$remote")" if [ "${url##https://}" = "$url" ]; then - https_url="${url##*@}" - https_url="https://${https_url/://}" + https_url="https://${url##*@}" + https_url="${https_url%%:*}/${https_url#*:}" $GIT remote set-url "$remote" "$https_url" $GIT remote set-url --push "$remote" "$url" else - ssh_url="${url##https://}" - ssh_url="git@${ssh_url/\//:}" + ssh_url="git@${url#https://}" + ssh_url="${ssh_url%%/*}:${ssh_url#*/}" $GIT remote set-url --push "$remote" "$ssh_url" fi