git: Add https-and-ssh to setup origin
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.
This commit is contained in:
@@ -19,12 +19,14 @@
|
||||
root = rev-parse --show-toplevel
|
||||
signoff = rebase --signoff
|
||||
ss = stash
|
||||
ssh-and-https = https-and-ssh
|
||||
|
||||
# Implemented as zsh functions or external programs
|
||||
checkout-worktree = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-checkout-worktree\""
|
||||
commit-last-msg = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-commit-last-msg\""
|
||||
filter-repo = !git-filter-repo
|
||||
flog = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/glog\""
|
||||
https-and-ssh = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-https-and-ssh\""
|
||||
make-fork = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-make-fork\""
|
||||
ssync = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-ssync\""
|
||||
submodule-rm = "!\"${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git/git-submodule-rm\""
|
||||
|
||||
20
.config/zsh/autoload/git/git-https-and-ssh
Executable file
20
.config/zsh/autoload/git/git-https-and-ssh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/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.
|
||||
|
||||
GIT="git"
|
||||
|
||||
origin="$($GIT remote -v | grep -Po '(?<=^origin\t).*(?= \(fetch\)$)')"
|
||||
|
||||
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"
|
||||
else
|
||||
ssh_origin="${origin##https://}"
|
||||
ssh_origin="git@${ssh_origin/\//:}"
|
||||
$GIT remote set-url --push origin "$ssh_origin"
|
||||
fi
|
||||
1
.config/zsh/autoload/git/git-ssh-and-https
Symbolic link
1
.config/zsh/autoload/git/git-ssh-and-https
Symbolic link
@@ -0,0 +1 @@
|
||||
git-https-and-ssh
|
||||
Reference in New Issue
Block a user