Files
dotfiles/.config/zsh/autoload/git/git-https-and-ssh
Julian Prein c6cdc6ec78 git:https-and-ssh: Swap the if blocks
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 ¯\_(ツ)_/¯
2025-01-21 18:08:18 +01:00

21 lines
551 B
Bash
Executable File

#!/bin/sh
# 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"
remote="${1:-origin}"
url="$($GIT remote get-url "$remote")"
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"
fi