In the rare case that no remote url containing `druckdev/dotfiles` exists, this should still (try to) work. This could be the case if I rename my username or the repo or in the even rarer case that somebody forks this... Quite ambitious.
19 lines
514 B
Bash
Executable File
19 lines
514 B
Bash
Executable File
#!/bin/sh
|
|
|
|
die() {
|
|
printf "$1" >&2
|
|
exit ${2:-1}
|
|
}
|
|
|
|
remote="$(git remote -v | grep -m1 "druckdev/dotfiles" | cut -f1)"
|
|
: "${remote:=origin}"
|
|
url="$(git remote get-url "$remote")"
|
|
! printf "$url" | grep -q '^git@' || die "Using ssh already.\n" 0
|
|
|
|
host="$(printf "$url" | cut -d/ -f3)"
|
|
grep -q "$host" "$HOME"/.ssh/known_hosts || die "No ssh key for $host found.\n"
|
|
|
|
ssh_url="$(printf "$url" | sed 's_^https\?://_git@_;s_/_:_')"
|
|
git remote set-url "$remote" "$ssh_url"
|
|
die "Set $remote remote url to $ssh_url\n" $?
|