mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-03 03:41:14 -03:00
Add string 'repeat' subcommand
This feature add the ability to repeat a string a given number of times. For example: string repeat -n 3 foo
This commit is contained in:
@@ -15,6 +15,8 @@ string match [(-a | --all)] [(-i | --ignore-case)] [(-r | --regex)]
|
||||
[(-n | --index)] [(-q | --quiet)] [(-v | --invert)] PATTERN [STRING...]
|
||||
string replace [(-a | --all)] [(-i | --ignore-case)] [(-r | --regex)]
|
||||
[(-q | --quiet)] PATTERN REPLACEMENT [STRING...]
|
||||
string repeat [(-n | --count)] [(-m | --max)] [(-N | --no-newline)]
|
||||
[(-q | --quiet)] [STRING...]
|
||||
\endfish
|
||||
|
||||
|
||||
@@ -48,6 +50,8 @@ The following subcommands are available:
|
||||
|
||||
- `replace` is similar to `match` but replaces non-overlapping matching substrings with a replacement string and prints the result. By default, PATTERN is treated as a literal substring to be matched. If `-r` or `--regex` is given, PATTERN is interpreted as a Perl-compatible regular expression, and REPLACEMENT can contain C-style escape sequences like `\t` as well as references to capturing groups by number or name as `$n` or `${n}`. Exit status: 0 if at least one replacement was performed, or 1 otherwise.
|
||||
|
||||
- `repeat` repeats the STRING `-n` or `--count` times. The `-m` or `--max` option will limit the number of outputed char (excluding the newline). This option can be used by itself or in conjuction with `--count`. If both `--count` and `--max` are present, max char will be outputed unless the final repeated string size is less than max, in that case, the string will repeat until count has been reached. Both `--count` and `--max` will accept a number greater than or equal to zero, in the case of zero, nothing will be outputed. If `-N` or `--no-newline` is given, the output won't contain a newline character at the end. Exit status: 0 if yielded string is not empty, 1 otherwise.
|
||||
|
||||
\subsection regular-expressions Regular Expressions
|
||||
|
||||
Both the `match` and `replace` subcommand support regular expressions when used with the `-r` or `--regex` option. The dialect is that of PCRE2.
|
||||
@@ -190,3 +194,19 @@ In general, special characters are special by default, so `a+` matches one or mo
|
||||
<outp>put a</outp>
|
||||
<outp>here</outp>
|
||||
\endfish
|
||||
|
||||
\subsection string-example-repeat Repeat Examples
|
||||
|
||||
\fish{cli-dark}
|
||||
>_ string repeat -n 2 'foo '
|
||||
<outp>foo foo</outp>
|
||||
|
||||
>_ echo foo | string repeat -n 2
|
||||
<outp>foofoo</outp>
|
||||
|
||||
>_ string repeat -n 2 -m 5 'foo'
|
||||
<outp>foofo</outp>
|
||||
|
||||
>_ string repeat -m 5 'foo'
|
||||
<outp>foofo</outp>
|
||||
\endfish
|
||||
|
||||
Reference in New Issue
Block a user