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

31 lines
759 B
Plaintext
Raw Normal View History

#!/bin/sh
# Translate different repo notations into ssh
# Usage:
# git repo <url>
# git repo <host> <repo> [user]
case "$1" in
2022-08-21 10:29:51 +00:00
(http*)
if expr "$1" : ".*:" >/dev/null
2023-06-16 08:47:24 +00:00
then echo "${1%/}" | sed "s|.*//\([^/]*\)/\(.*\)|git@\1:\2.git|"
2022-08-21 10:29:51 +00:00
exit
else http=$1 && shift
fi;;
(git:*|ssh:*)
echo "$1"
exit;;
esac
2024-01-12 16:53:07 +00:00
host=$1
case $host in
2022-08-21 10:29:51 +00:00
(socha) user=software-challenge; host=git@github.com;;
2024-01-12 16:53:07 +00:00
(hub|github) host=git@github.com;;
2022-08-21 10:29:51 +00:00
(lab) host=git@gitlab.com;;
2024-01-12 16:53:07 +00:00
(jf) host=gitea@git.jfischer.org;;
2024-04-08 11:02:09 +00:00
(ftt|"") host=git@forge.ftt.gmbh; user=janek;;
2022-08-21 10:29:51 +00:00
esac
user=${3:-${user:-$(git config user.name)}}
2023-09-27 13:38:23 +00:00
repo=${2:-$(basename $(git root))}
2022-08-21 10:29:51 +00:00
if test "$http"
then echo "$http://${host#git*@}/$user/$repo.git"
else echo "$host:$user/$repo.git"
fi