Skip to content

Instantly share code, notes, and snippets.

@Cologler
Created July 4, 2022 13:02
Show Gist options
  • Save Cologler/6cf4183ac326297e9ccbe2de1a9e6a5a to your computer and use it in GitHub Desktop.
Save Cologler/6cf4183ac326297e9ccbe2de1a9e6a5a to your computer and use it in GitHub Desktop.
bulk clone repos
# bulk clone repos from config list.
#
# to run the script, try:
# ^nu 'bulk-git-clone.nu' .\git_repos.yaml
def get-qualname [repo_url: string] {
let $name_parts = if $repo_url =~ '^https?://' {
let $match = ($repo_url | parse -r '^https?://(?P<host>.+)/(?P<user>.+)/(?P<repo>.+)$')
if ($match | length) > 0 {
[$match.host.0, $match.user.0, $match.repo.0]
}
} else if $repo_url =~ '^git@' {
let $match = ($repo_url | parse -r '^git@(?P<host>.+):(?P<user>.+)/(?P<repo>.+)\.git$')
if ($match | length) > 0 {
[$match.host.0, $match.user.0, $match.repo.0]
}
}
$name_parts | str collect '#'
}
def main [cfg: string] {
let $cfg_ctn = open $cfg
let $dst_base_dir = ($cfg | path dirname | path expand)
$cfg_ctn | get repos | each { |repo|
let $repo_type = ($repo | describe)
if ($repo_type == string) {
let $repo_url = $repo
let $dst_dir = ($dst_base_dir | path join (get-qualname $repo_url))
if not ($dst_dir | path exists) {
git clone $repo $dst_dir --depth 1
}
}
}
}
repos:
- git@github.com:nushell/nu_scripts.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment