mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
docs/cmds/string: Improve synopsis
This both formats it as a code-block, and adds the synopsis of each subcommand to the corresponding section again so you don't need to scroll back-and-forth so much. [ci skip]
This commit is contained in:
parent
ebc0bee404
commit
b8570a9e8a
1 changed files with 56 additions and 23 deletions
|
@ -4,28 +4,33 @@ string - manipulate strings
|
|||
Synopsis
|
||||
--------
|
||||
|
||||
string escape [(-n | --no-quoted)] [--style=xxx] [STRING...]
|
||||
string join [(-q | --quiet)] SEP [STRING...]
|
||||
string join0 [(-q | --quiet)] [STRING...]
|
||||
string length [(-q | --quiet)] [STRING...]
|
||||
string lower [(-q | --quiet)] [STRING...]
|
||||
string match [(-a | --all)] [(-e | --entire)] [(-i | --ignore-case)] [(-r | --regex)]
|
||||
[(-n | --index)] [(-q | --quiet)] [(-v | --invert)] PATTERN [STRING...]
|
||||
string repeat [(-n | --count) COUNT] [(-m | --max) MAX] [(-N | --no-newline)]
|
||||
[(-q | --quiet)] [STRING...]
|
||||
string replace [(-a | --all)] [(-f | --filter)] [(-i | --ignore-case)] [(-r | --regex)]
|
||||
[(-q | --quiet)] PATTERN REPLACEMENT [STRING...]
|
||||
string split [(-m | --max) MAX] [(-n | --no-empty)] [(-q | --quiet)] [(-r | --right)] SEP
|
||||
[STRING...]
|
||||
string split0 [(-m | --max) MAX] [(-n | --no-empty)] [(-q | --quiet)] [(-r | --right)]
|
||||
[STRING...]
|
||||
string sub [(-s | --start) START] [(-l | --length) LENGTH] [(-q | --quiet)]
|
||||
[STRING...]
|
||||
string trim [(-l | --left)] [(-r | --right)] [(-c | --chars CHARS)]
|
||||
[(-q | --quiet)] [STRING...]
|
||||
string unescape [--style=xxx] [STRING...]
|
||||
string upper [(-q | --quiet)] [STRING...]
|
||||
``string escape [(-n | --no-quoted)] [--style=xxx] [STRING...]``
|
||||
|
||||
``string join [(-q | --quiet)] SEP [STRING...]``
|
||||
|
||||
``string join0 [(-q | --quiet)] [STRING...]``
|
||||
|
||||
``string length [(-q | --quiet)] [STRING...]``
|
||||
|
||||
``string lower [(-q | --quiet)] [STRING...]``
|
||||
|
||||
``string match [(-a | --all)] [(-e | --entire)] [(-i | --ignore-case)] [(-r | --regex)] [(-n | --index)] [(-q | --quiet)] [(-v | --invert)] PATTERN [STRING...]``
|
||||
|
||||
``string repeat [(-n | --count) COUNT] [(-m | --max) MAX] [(-N | --no-newline)] [(-q | --quiet)] [STRING...]``
|
||||
|
||||
``string replace [(-a | --all)] [(-f | --filter)] [(-i | --ignore-case)] [(-r | --regex)] [(-q | --quiet)] PATTERN REPLACEMENT [STRING...]``
|
||||
|
||||
``string split [(-m | --max) MAX] [(-n | --no-empty)] [(-q | --quiet)] [(-r | --right)] SEP [STRING...]``
|
||||
|
||||
``string split0 [(-m | --max) MAX] [(-n | --no-empty)] [(-q | --quiet)] [(-r | --right)] [STRING...]``
|
||||
|
||||
``string sub [(-s | --start) START] [(-l | --length) LENGTH] [(-q | --quiet)] [STRING...]``
|
||||
|
||||
``string trim [(-l | --left)] [(-r | --right)] [(-c | --chars CHARS)] [(-q | --quiet)] [STRING...]``
|
||||
|
||||
``string unescape [--style=xxx] [STRING...]``
|
||||
|
||||
``string upper [(-q | --quiet)] [STRING...]``
|
||||
|
||||
|
||||
Description
|
||||
|
@ -41,8 +46,10 @@ Most subcommands accept a ``-q`` or ``--quiet`` switch, which suppresses the usu
|
|||
|
||||
The following subcommands are available.
|
||||
|
||||
"escape" subcommand
|
||||
-------------------
|
||||
"escape" and "unescape" subcommands
|
||||
-----------------------------------
|
||||
|
||||
``string escape [(-n | --no-quoted)] [--style=xxx] [STRING...]``
|
||||
|
||||
``string escape`` escapes each STRING in one of three ways. The first is ``--style=script``. This is the default. It alters the string such that it can be passed back to ``eval`` to produce the original argument again. By default, all special characters are escaped, and quotes are used to simplify the output when possible. If ``-n`` or ``--no-quoted`` is given, the simplifying quoted format is not used. Exit status: 0 if at least one string was escaped, or 1 otherwise.
|
||||
|
||||
|
@ -52,31 +59,43 @@ The following subcommands are available.
|
|||
|
||||
``--style=regex`` escapes an input string for literal matching within a regex expression. The string is first converted to UTF-8 before being encoded.
|
||||
|
||||
``string unescape [--style=xxx] [STRING...]``
|
||||
|
||||
``string unescape`` performs the inverse of the ``string escape`` command. If the string to be unescaped is not properly formatted it is ignored. For example, doing ``string unescape --style=var (string escape --style=var $str)`` will return the original string. There is no support for unescaping ``--style=regex``.
|
||||
|
||||
"join" subcommand
|
||||
-----------------
|
||||
|
||||
``string join [(-q | --quiet)] SEP [STRING...]``
|
||||
|
||||
``string join`` joins its STRING arguments into a single string separated by SEP, which can be an empty string. Exit status: 0 if at least one join was performed, or 1 otherwise.
|
||||
|
||||
"join0" subcommand
|
||||
------------------
|
||||
|
||||
``string join0 [(-q | --quiet)] [STRING...]``
|
||||
|
||||
``string join`` joins its STRING arguments into a single string separated by the zero byte (NUL), and adds a trailing NUL. This is most useful in conjunction with tools that accept NUL-delimited input, such as ``sort -z``. Exit status: 0 if at least one join was performed, or 1 otherwise.
|
||||
|
||||
"length" subcommand
|
||||
-------------------
|
||||
|
||||
``string length [(-q | --quiet)] [STRING...]``
|
||||
|
||||
``string length`` reports the length of each string argument in characters. Exit status: 0 if at least one non-empty STRING was given, or 1 otherwise.
|
||||
|
||||
"lower" subcommand
|
||||
------------------
|
||||
|
||||
``string lower [(-q | --quiet)] [STRING...]``
|
||||
|
||||
``string lower`` converts each string argument to lowercase. Exit status: 0 if at least one string was converted to lowercase, else 1. This means that in conjunction with the ``-q`` flag you can readily test whether a string is already lowercase.
|
||||
|
||||
"match" subcommand
|
||||
------------------
|
||||
|
||||
``string match [(-a | --all)] [(-e | --entire)] [(-i | --ignore-case)] [(-r | --regex)] [(-n | --index)] [(-q | --quiet)] [(-v | --invert)] PATTERN [STRING...]``
|
||||
|
||||
``string match`` tests each STRING against PATTERN and prints matching substrings. Only the first match for each STRING is reported unless ``-a`` or ``--all`` is given, in which case all matches are reported.
|
||||
|
||||
If you specify the ``-e`` or ``--entire`` then each matching string is printed including any prefix or suffix not matched by the pattern (equivalent to ``grep`` without the ``-o`` flag). You can, obviously, achieve the same result by prepending and appending ``*`` or ``.*`` depending on whether or not you have specified the ``--regex`` flag. The ``--entire`` flag is simply a way to avoid having to complicate the pattern in that fashion and make the intent of the ``string match`` clearer. Without ``--entire`` and ``--regex``, a PATTERN will need to match the entire STRING before it will be reported.
|
||||
|
@ -94,11 +113,15 @@ Exit status: 0 if at least one match was found, or 1 otherwise.
|
|||
"repeat" subcommand
|
||||
-------------------
|
||||
|
||||
``string repeat [(-n | --count) COUNT] [(-m | --max) MAX] [(-N | --no-newline)] [(-q | --quiet)] [STRING...]``
|
||||
|
||||
``string repeat`` repeats the STRING ``-n`` or ``--count`` times. The ``-m`` or ``--max`` option will limit the number of outputted char (excluding the newline). This option can be used by itself or in conjunction 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.
|
||||
|
||||
"replace" subcommand
|
||||
--------------------
|
||||
|
||||
``string replace [(-a | --all)] [(-f | --filter)] [(-i | --ignore-case)] [(-r | --regex)] [(-q | --quiet)] PATTERN REPLACEMENT [STRING...]``
|
||||
|
||||
``string replace`` is similar to ``string 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}``.
|
||||
|
@ -110,6 +133,8 @@ Exit status: 0 if at least one replacement was performed, or 1 otherwise.
|
|||
"split" subcommand
|
||||
------------------
|
||||
|
||||
``string split [(-m | --max) MAX] [(-n | --no-empty)] [(-q | --quiet)] [(-r | --right)] SEP [STRING...]``
|
||||
|
||||
``string split`` splits each STRING on the separator SEP, which can be an empty string. If ``-m`` or ``--max`` is specified, at most MAX splits are done on each STRING. If ``-r`` or ``--right`` is given, splitting is performed right-to-left. This is useful in combination with ``-m`` or ``--max``. With ``-n`` or ``--no-empty``, empty results are excluded from consideration (e.g. ``hello\n\nworld`` would expand to two strings and not three). Exit status: 0 if at least one split was performed, or 1 otherwise.
|
||||
|
||||
See also ``read --delimiter``.
|
||||
|
@ -117,6 +142,8 @@ See also ``read --delimiter``.
|
|||
"split0" subcommand
|
||||
-------------------
|
||||
|
||||
``string split0 [(-m | --max) MAX] [(-n | --no-empty)] [(-q | --quiet)] [(-r | --right)] [STRING...]``
|
||||
|
||||
``string split0`` splits each STRING on the zero byte (NUL). Options are the same as ``string split`` except that no separator is given.
|
||||
|
||||
``split0`` has the important property that its output is not further split when used in a command substitution, allowing for the command substitution to produce elements containing newlines. This is most useful when used with Unix tools that produce zero bytes, such as ``find -print0`` or ``sort -z``. See split0 examples below.
|
||||
|
@ -124,16 +151,22 @@ See also ``read --delimiter``.
|
|||
"sub" subcommand
|
||||
----------------
|
||||
|
||||
``string sub [(-s | --start) START] [(-l | --length) LENGTH] [(-q | --quiet)] [STRING...]``
|
||||
|
||||
``string sub`` prints a substring of each string argument. The start of the substring can be specified with ``-s`` or ``--start`` followed by a 1-based index value. Positive index values are relative to the start of the string and negative index values are relative to the end of the string. The default start value is 1. The length of the substring can be specified with ``-l`` or ``--length``. If the length is not specified, the substring continues to the end of each STRING. Exit status: 0 if at least one substring operation was performed, 1 otherwise.
|
||||
|
||||
"trim" subcommand
|
||||
-----------------
|
||||
|
||||
``string trim [(-l | --left)] [(-r | --right)] [(-c | --chars CHARS)] [(-q | --quiet)] [STRING...]``
|
||||
|
||||
``string trim`` removes leading and trailing whitespace from each STRING. If ``-l`` or ``--left`` is given, only leading whitespace is removed. If ``-r`` or ``--right`` is given, only trailing whitespace is trimmed. The ``-c`` or ``--chars`` switch causes the characters in CHARS to be removed instead of whitespace. Exit status: 0 if at least one character was trimmed, or 1 otherwise.
|
||||
|
||||
"upper" subcommand
|
||||
------------------
|
||||
|
||||
``string upper [(-q | --quiet)] [STRING...]``
|
||||
|
||||
``string upper`` converts each string argument to uppercase. Exit status: 0 if at least one string was converted to uppercase, else 1. This means that in conjunction with the ``-q`` flag you can readily test whether a string is already uppercase.
|
||||
|
||||
Regular Expressions
|
||||
|
|
Loading…
Reference in a new issue