From c6cdc6ec78353786df90624183a34f862fd4ca8f Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Tue, 21 Jan 2025 18:08:18 +0100 Subject: [PATCH] git:https-and-ssh: Swap the if blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My brain assumes that the first block handles the case of the url being an https one if I read http in the condition. Swap them and negate the condition for better readability. This might be a symptom of this condition being to complex, but well - it's shell scripting ¯\_(ツ)_/¯ --- .config/zsh/autoload/git/git-https-and-ssh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.config/zsh/autoload/git/git-https-and-ssh b/.config/zsh/autoload/git/git-https-and-ssh index 6cc5593..b3a2906 100755 --- a/.config/zsh/autoload/git/git-https-and-ssh +++ b/.config/zsh/autoload/git/git-https-and-ssh @@ -8,13 +8,13 @@ GIT="git" remote="${1:-origin}" url="$($GIT remote get-url "$remote")" -if [ "${url##https://}" = "$url" ]; then +if [ "${url##https://}" != "$url" ]; then + ssh_url="${url#https://}" + ssh_url="git@${ssh_url/\//:}" + $GIT remote set-url --push "$remote" "$ssh_url" +else https_url="${url##*@}" https_url="https://${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/\//:}" - $GIT remote set-url --push "$remote" "$ssh_url" fi