nu_scripts/stdlib-candidate
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
..
std-rfc [stdlib-candidate] Clean up file bulk-rename a little (#798) 2024-03-30 16:19:06 -05:00
tests [stdlib-candidate] Clean up file bulk-rename a little (#798) 2024-03-30 16:19:06 -05:00
nupm.nuon Refactor stdlib-candidate for nupm (#790) 2024-03-16 13:57:05 +02:00
README.md Add str append to stdlib-candidate (#626) 2023-09-30 17:13:46 -05:00

std-lib candidate

This folder is where we can add scripts that might want to be in std-lib at some point. It can serve both as a holding place for scripts that are waiting on nushell changes, as well as a place to develop and discuss such scripts.