A place to share Nushell scripts with each other
Go to file
Texas Toland 268201e4ac
[stdlib-candidate] Clean up file bulk-rename a little (#798)
[Generated diff](https://www.diffnow.com/report/xmq4f) for command
because move broke it.

- No `file` prefix similar to other [filesystem
commands](https://www.nushell.sh/commands/categories/filesystem.html)
- Input paths instead of directory param for filters or globbing
- Record closure param with original path (`$in` is still stem)
- `--verbose` table output
- `--no-exectute` for dry run with `--verbose`
- Shorthand flags
- Parallel renaming for large directories
- More tests

@amtoine Request feedback 🙏🏼 Happy to revise ot revert anything!

```console
❯ bulk-rename -h
Rename bulk input files in parallel using a closure.

The reason behind this command is quite simple:
- Sometimes one receives a bunch of files with integer ids: 1, 2, 3, ...
- These ids come rarely with padding... i.e. 1 instead of 001 when there are 3-digit ids
- This means that file with id 9 will be sorted way after file with id 1000

This command allows to do such a task!

Examples:
  Rename `.mise.toml` files to `.mise.local.toml` recursively
  > glob **/.mise.toml | bulk-rename { str append .local }

  Rename files in `/foo` with a name that has an id to have 3 digits with 0-padding
  > ls /foo | bulk-rename { |path|
     if $path.input.type == file {
       $path.stem | parse "some_format_{id}"
         | get 0
         | update id { fill --alignment r --character 0 --width 3 }
         | $"some_format_($in.id)"
     }
     # else skip dirs
   }

Usage:
  > main {flags} <update_stem>

Flags:
  -v, --verbose - Show which files were renamed, if any
  -n, --no-execute - Do not make any changes; add --verbose to see what would be made
whitespace bug: nushell/nushell#12264
  -h, --help - Display the help message for this command

Parameters:
  update_stem <closure()>: The code to rename the file stem: receives the old stem as input and a record param with both `stem` and `input` keys

Input/output types:
  ╭───┬───────────┬─────────────────────────────────╮
  │ # │   input   │             output              │
  ├───┼───────────┼─────────────────────────────────┤
  │ 0 │ list<any> │ nothing                         │
  │ 1 │ list<any> │ table<old: string, new: string> │
  ╰───┴───────────┴─────────────────────────────────╯
```
2024-03-30 16:19:06 -05:00
.github/workflows Refactor toolkit.nu (#791) 2024-03-15 19:17:31 +02:00
aliases Add chezmoi aliases (#788) 2024-03-12 10:55:37 -05:00
assets move assets so they're more accessible (#445) 2023-04-12 08:29:47 -05:00
before_v0.60 🐛 fix more parser errors (#783) 2024-03-15 21:10:27 -05:00
benchmarks fix removed commands (#645) 2023-10-19 19:35:23 +02:00
custom-completions add rye completions (#802) 2024-03-27 18:36:51 -05:00
custom-menus move the extra menus of Nushell into custom-menus/extra/ (#550) 2023-07-21 10:44:27 +02:00
example-config export env is not in nushell (#529) 2023-06-17 07:48:08 -05:00
make_release Add option list-merged-pr --table (#774) 2024-03-07 06:19:29 -06:00
modules kube refine for backup (#793) 2024-03-30 07:14:45 -05:00
nu-hooks rename package files (#701) 2024-02-18 16:23:47 +01:00
sourced 🐛 fix a couple of parser errors (#782) 2024-03-10 14:05:01 -05:00
stdlib-candidate [stdlib-candidate] Clean up file bulk-rename a little (#798) 2024-03-30 16:19:06 -05:00
themes Support for catppuccin-latte (#741) 2024-03-07 06:18:50 -06:00
.gitattributes Add Nushell Language detect for linguist (#532) 2023-06-21 11:36:01 +03:00
.gitignore add a nu-check verification CI (#771) 2024-03-12 20:48:08 +01:00
LICENSE Initial commit 2021-01-23 07:33:45 +13:00
README.md 🐛 fix more parser errors (#783) 2024-03-15 21:10:27 -05:00
toolkit.nu Refactor toolkit.nu (#791) 2024-03-15 19:17:31 +02:00

Nushell Scripts

CI

This is a place to share Nushell scripts with each other. If you'd like to share your scripts, fork this repository, and create a PR that adds it to the repo.

Sections

Running Scripts

You can run nushell scripts in a few different ways.

  1. You can type nu <script name>.
  2. From with nushell, you can type source <script name> and if the script is just a bunch of commands it will run the script. If the script is a custom command it will load those custom commands into your current scope so you can run them like any other command.