Add script to switch between HTTP and SSH remotes

This commit is contained in:
askiiart 2024-03-18 18:40:51 -05:00
parent bfca32f915
commit 07c5b2edfd
Signed by untrusted user who does not match committer: askiiart
GPG key ID: BC3800E55FB54D67

View file

@ -23,5 +23,25 @@ alias nrb-rb="sudo NIXPKGS_ALLOW_INSECURE=1 nixos-rebuild build --upgrade-all --
alias hms="NIXPKGS_ALLOW_INSECURE=1 home-manager switch" alias hms="NIXPKGS_ALLOW_INSECURE=1 home-manager switch"
alias hmb="NIXPKGS_ALLOW_INSECURE=1 home-manager build" alias hmb="NIXPKGS_ALLOW_INSECURE=1 home-manager build"
# git # git
alias git-us="git submodule update --init --recursive" alias git-us="git submodule update --init --recursive"
# switch between SSH and HTTPS remotes
alias git-remote-switch="python3 -c \"import subprocess
remote = subprocess.getoutput('git branch -vv')
remote = remote[remote.find('[') + 1 : remote.find('/')]
old_url = subprocess.getoutput(f'git remote get-url {remote}')
if old_url.startswith('https://'):
new_url = old_url[8:]
new_url = new_url[: new_url.find('/')] + ':' + new_url[new_url.find('/') + 1 :]
new_url = f'git@{new_url}'
else:
new_url = old_url[4:]
new_url = new_url.replace(':', '/')
new_url = f'https://{new_url}'
exit(subprocess.getstatusoutput(f'git remote set-url {remote} {new_url}')[0])\""