dotfiles/.local/bin/scripts/git-repo

24 lines
680 B
Plaintext
Raw Normal View History

#!/bin/sh
# Translate different repo notations into ssh
# Usage:
# git repo <url>
# git repo <host> <repo> [user]
2022-07-05 10:15:47 +00:00
test "$1" = https && https=true && shift
case "$1" in
(http*) echo "$1" | sed "s|.*//\([^/]*\)/\(.*\)|git@\1:\2.git|" ;;
2022-07-05 10:15:47 +00:00
(git:*|ssh:*) echo "$1" ;;
(*)
2021-11-17 14:55:46 +00:00
case $1 in
2021-12-16 22:04:50 +00:00
(socha) user=software-challenge; host=git@github.com;;
2021-11-17 14:55:46 +00:00
(hub) host=git@github.com;;
(lab) host=git@gitlab.com;;
(*) host=${1:-gitea@git.jfischer.org};;
2021-11-17 14:55:46 +00:00
esac
2022-07-05 10:15:47 +00:00
user=${3:-${user:-$(git config user.name)}}
repo=${2:-$(basename $PWD)}
if test "$https"
then echo "https://${host#git*@}/$user/$repo.git"
2022-07-05 10:15:47 +00:00
else echo "$host:$user/$repo.git"
fi
esac