meta:git-remote: Don't hardcode origin as remote

As I know how the url should look like I can allow the default remote
being named differently.
This commit is contained in:
2022-01-22 00:02:36 +01:00
parent 5155cbbed1
commit 4c3dfc4c52

View File

@@ -5,12 +5,13 @@ die() {
exit ${2:-1} exit ${2:-1}
} }
remote="$(git remote get-url origin)" remote="$(git remote -v | grep -m1 "druckdev/dotfiles" | cut -f1)"
! printf "$remote" | grep -q '^git@' || die "Using ssh already.\n" 0 url="$(git remote get-url "$remote")"
! printf "$url" | grep -q '^git@' || die "Using ssh already.\n" 0
host="$(printf "$remote" | cut -d/ -f3)" host="$(printf "$url" | cut -d/ -f3)"
grep -q "$host" "$HOME"/.ssh/known_hosts || die "No ssh key for $host found.\n" grep -q "$host" "$HOME"/.ssh/known_hosts || die "No ssh key for $host found.\n"
ssh_remote="$(printf "$remote" | sed 's_^https\?://_git@_;s_/_:_')" ssh_url="$(printf "$url" | sed 's_^https\?://_git@_;s_/_:_')"
git remote set-url origin "$ssh_remote" git remote set-url "$remote" "$ssh_url"
die "Set origin remote url to $ssh_remote\n" $? die "Set $remote remote url to $ssh_url\n" $?