This commit is contained in:
parent
a4b5039da2
commit
665525fb9e
1 changed files with 42 additions and 0 deletions
42
modules/scripts/clone.nix
Normal file
42
modules/scripts/clone.nix
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
{
|
||||||
|
flake.modules.homeManager.base =
|
||||||
|
{ pkgs, ... }:
|
||||||
|
{
|
||||||
|
home.packages = [
|
||||||
|
(pkgs.writeShellApplication {
|
||||||
|
name = "clone";
|
||||||
|
|
||||||
|
runtimeInputs = with pkgs; [ git ];
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
repo_url="$1"
|
||||||
|
repo_url="''${repo_url%.git}"
|
||||||
|
|
||||||
|
if [[ "$repo_url" =~ ^(git@|https://|ssh://forgejo@)?([^:/]+)[:/](.*)/(.*)$ ]]; then
|
||||||
|
domain="''${BASH_REMATCH[2]}"
|
||||||
|
|
||||||
|
if [[ "$domain" == "ssh.oliverdavies.uk" ]]; then
|
||||||
|
domain="code.oliverdavies.uk"
|
||||||
|
fi
|
||||||
|
|
||||||
|
user="''${BASH_REMATCH[3]}"
|
||||||
|
name="''${BASH_REMATCH[4]}"
|
||||||
|
|
||||||
|
user_path="$XDG_REPOS_DIR/$domain/$user"
|
||||||
|
repo_path="$user_path/$name"
|
||||||
|
|
||||||
|
[[ -d "$repo_path" ]] && t "$repo_path" && exit 0
|
||||||
|
|
||||||
|
mkdir -pv "$repo_path"
|
||||||
|
|
||||||
|
git clone "$repo_url" "$repo_path"
|
||||||
|
|
||||||
|
t "$repo_path"
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue