#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix

# use like `eval $(sane-clone tuba)` to clone and cd into a tuba checkout

srcattr="$1.src"
basedir=/home/colin/ref/repos

# fetchFromGitHub: provides src.{gitRepoUrl,owner,repo}
# fetchFromGitLab: provides src.gitRepoUrl only
repourl="$(nix eval --raw /home/colin/dev/nixos#$srcattr.gitRepoUrl)"
repoowner="$(nix eval --raw /home/colin/dev/nixos#$srcattr.owner)"
reponame="$(nix eval --raw /home/colin/dev/nixos#$srcattr.repo)"

ownerdir="$basedir/$repoowner"
clonedir="$ownerdir/$reponame"

mkdir -p "$ownerdir"
git clone "$repourl" "$clonedir"

# drop the user into the checkout
echo "cd $clonedir"
cd "$clonedir"
