mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
✨ clone all
script (#781)
Hi! I did a script to clone multiple repos of github in a single folder I clone everything I intend to work when I reset my pc Instructions incluided!
This commit is contained in:
parent
5e51b23b1f
commit
1ccc379f38
2 changed files with 111 additions and 0 deletions
64
modules/clone-all/README.md
Normal file
64
modules/clone-all/README.md
Normal file
|
@ -0,0 +1,64 @@
|
|||
# Clone all
|
||||
|
||||
Do you want to automate cloning a list repos into a folder? This script is for you!
|
||||
|
||||
## Requirements:
|
||||
- [`gh` cli](https://github.com/cli/cli)
|
||||
|
||||
## How to use it
|
||||
|
||||
Load the script:
|
||||
|
||||
- if you have cloned the repo before:
|
||||
|
||||
```nushell env.nu
|
||||
source ~/your/directory/to/nu_scripts/modules/clone-all/clone-all.nu
|
||||
```
|
||||
|
||||
or if you have the file, and you want it to use in a nushell session:
|
||||
|
||||
```nushell
|
||||
use clone-all.nu *
|
||||
# and it's ready to use in the current prompt!
|
||||
```
|
||||
|
||||
Then, create a list of github routes to repositories `ORGANIZATION_NAME/REPO`
|
||||
like this:
|
||||
|
||||
```nu
|
||||
let list_of_repos = [
|
||||
"nushell/nushell"
|
||||
"nushell/nu_scripts"
|
||||
"nushell/vscode-nushell-lang"
|
||||
]
|
||||
```
|
||||
|
||||
And then you need to pass that variable and a destination folder
|
||||
|
||||
```nu
|
||||
clone all $list_of_repos $"($env.home)/other-repos/nu_repos"
|
||||
```
|
||||
|
||||
## Tips
|
||||
|
||||
I (@AucaCoyan) use it for cloning both org repos and my forks
|
||||
|
||||
```nushell
|
||||
let nushell_repos = [
|
||||
"nushell/nushell"
|
||||
"nushell/nu_scripts"
|
||||
"nushell/vscode-nushell-lang"
|
||||
]
|
||||
|
||||
clone all $nushell_repos $"($env.home)/other-repos/nu"
|
||||
|
||||
let nushell_forks = [
|
||||
"AucaCoyan/nushell"
|
||||
"AucaCoyan/nu_scripts"
|
||||
"AucaCoyan/vscode-nushell-lang"
|
||||
]
|
||||
|
||||
clone all $nushell_forks $"($env.home)/repos"
|
||||
```
|
||||
|
||||
and do that with every gh org (work or open source!)
|
47
modules/clone-all/clone-all.nu
Normal file
47
modules/clone-all/clone-all.nu
Normal file
|
@ -0,0 +1,47 @@
|
|||
# grabs the repo name of a github (ORG/repo) string
|
||||
#
|
||||
# for exaple
|
||||
# grab repo name "organization/my_special_repo"
|
||||
# returns "myspecial_repo"
|
||||
|
||||
# Grabs the repo name of a github (ORG/repo) string
|
||||
def "grab repo name" [ghrepo: string]: [string -> string] {
|
||||
$ghrepo | split column "/" | get column2 | last
|
||||
}
|
||||
|
||||
# Generic fn to clone all repos of one organization into a specific folder
|
||||
#
|
||||
# # Parameters
|
||||
# `list_of_repos` is a list of <ORG/REPO> from github
|
||||
# for example:
|
||||
# ```nu
|
||||
# let list_of_repos = [
|
||||
# "nushell/nushell"
|
||||
# "nushell/nu_scripts"
|
||||
# "nushell/vscode-nushell-lang"
|
||||
# ]
|
||||
#
|
||||
# and destination is the location where those repos are cloned
|
||||
# $ use clone-all.nu *
|
||||
# $ clone all ['nushell/nu_scripts'] /home/my-dir/
|
||||
# equals
|
||||
# gh repo clone nushell/nu_scripts /home/my-dir/nu_scripts
|
||||
# (note that it doesn't create the organization folder)
|
||||
|
||||
# Clones all the `list_of_repos` into `destination` folder
|
||||
export def "clone all" [list_of_repos: list<string>, destination: path] {
|
||||
print $" creating ($destination) folder"
|
||||
mkdir $destination
|
||||
|
||||
for $repo in $list_of_repos {
|
||||
let repo_name = grab repo name $repo
|
||||
let single_repo_dir = $"($destination)/($repo_name)"
|
||||
if ($single_repo_dir | path exists) {
|
||||
print $"\n repo ($single_repo_dir) exists, skipping"
|
||||
continue
|
||||
} else {
|
||||
print $"\n cloning ($repo)"
|
||||
gh repo clone $repo $single_repo_dir
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue