#shell #string #parser #template-string #template

bin+lib nu-plugin-bexpand

A brace expansion plugin compatible with Bash for nushell

16 stable releases

new 1.3.5 Apr 3, 2024
1.3.4 Mar 6, 2024
1.3.3 Feb 29, 2024
1.3.1 Nov 15, 2023
1.1.5 Jun 25, 2023

#603 in Parser implementations

Download history 133/week @ 2024-02-14 5/week @ 2024-02-21 285/week @ 2024-02-28 154/week @ 2024-03-06 21/week @ 2024-03-13

462 downloads per month

MPL-2.0 and maybe CC-PDDC

16KB
168 lines

nu-plugin-bexpand

Bash-style brace expansion in nushell.

Format and Functionality

The format specification and functionality is fully explained in the bexpand crate, which implements the parser and iterator types independent of nushell.

Usage

> cargo install nu-plugin-bexpand
...

> register ~/.cargo/bin/nu_plugin_bexpand

> help str bexpand
Bash-style brace expansion

Usage:
  > str bexpand 

Flags:
  -h, --help - Display the help message for this command

Signatures:
  <string> | str bexpand -> list<string>
  list<string> | str bexpand -> list<string>

Examples:
  Get a list of standard nushell config items
  > '~/config/nushell/{env,config,plugin}.nu' | str bexpand

> 'a{b,c,d{๐Ÿฅฐ..๐Ÿฅด..2}e}f' | str bexpand
โ•ญโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ 0 โ”‚ abf    โ”‚
โ”‚ 1 โ”‚ acf    โ”‚
โ”‚ 2 โ”‚ ad๐Ÿฅฐef โ”‚
โ”‚ 3 โ”‚ ad๐Ÿฅฒef โ”‚
โ”‚ 4 โ”‚ ad๐Ÿฅดef โ”‚
โ•ฐโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
 
> 'a{1..3}c{4..6..2}b' | str bexpand
โ•ญโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ 0 โ”‚ a1c4b โ”‚
โ”‚ 1 โ”‚ a1c6b โ”‚
โ”‚ 2 โ”‚ a2c4b โ”‚
โ”‚ 3 โ”‚ a2c6b โ”‚
โ”‚ 4 โ”‚ a3c4b โ”‚
โ”‚ 5 โ”‚ a3c6b โ”‚
โ•ฐโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

> [a{๐Ÿค..๐Ÿค’}b c{๐Ÿง›..๐Ÿฆœ..31}d e{15..-23..8}f] | str bexpand
โ•ญโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚  0 โ”‚ a๐Ÿคb  โ”‚
โ”‚  1 โ”‚ a๐Ÿค‘b  โ”‚
โ”‚  2 โ”‚ a๐Ÿค’b  โ”‚
โ”‚  3 โ”‚ c๐Ÿง›d  โ”‚
โ”‚  4 โ”‚ c๐Ÿฆผd  โ”‚
โ”‚  5 โ”‚ c๐Ÿฆd  โ”‚
โ”‚  6 โ”‚ e15f  โ”‚
โ”‚  7 โ”‚ e7f   โ”‚
โ”‚  8 โ”‚ e-1f  โ”‚
โ”‚  9 โ”‚ e-9f  โ”‚
โ”‚ 10 โ”‚ e-17f โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

> '{0..๐Ÿงฟ..129300}' | str bexpand
โ•ญโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ•ฎ
โ”‚ 0 โ”‚ 0  โ”‚
โ”‚ 1 โ”‚ ๐Ÿฅ„ โ”‚
โ•ฐโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ•ฏ

> ['success{a,b,c}test' 'fail{test'] | str bexpand
Error:   ร— Brace expression failed to parse
   โ•ญโ”€[entry #13:1:1]
 1 โ”‚ ['success{a,b,c}test' 'fail{test'] | str bexpand
   ยท                       โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€
   ยท                            โ•ฐโ”€โ”€ 0: at line 1, in Eof:
fail{test
    ^


   โ•ฐโ”€โ”€โ”€โ”€

> "{\u{D7FF}..\u{E000}}" | str bexpand
Error:   ร— Expression failed to generate
   โ•ญโ”€[entry #15:1:1]
 1 โ”‚ "{\u{D7FF}..\u{E000}}" | str bexpand
   ยท                          โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€
   ยท                               โ•ฐโ”€โ”€ converted integer out of range for `char`
   โ•ฐโ”€โ”€โ”€โ”€

Dependencies

~15โ€“51MB
~772K SLoC