mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-01 04:41:14 -03:00
New -n flag for string join. (#8774)
* New -n flag for string join command. This is an argument that excludes empty result items. Fixes #8351 * New documentation for string-join. The new argument --no-empty was added at string-join manpage. * New completions for the new -n flag for string join. * Remove the documentation of the new -n flag of string join0 The reason to remove this new argument in the join0 is that this flag basically doesn't make any difference in the join0. * Refactor the validation for the string join. The string join command was using the length of the argument, this commit changes the validation to use the empty function. * Revert #4b56ab452 The reason for the revert is thath the build broke on the ubuntu in the Github actions. * Revert #e72e239a1 The reason the compilation on GitHub broke is that the test was weird, it didn't even run it, Common CI systems are typically very very resource-constrained. * Resolve conflicts in the string-join.rst. * Resolve conflicts in the "string-join.rst". commit #1242d0fd7 not fixed all conflicts.
This commit is contained in:
@@ -18,7 +18,7 @@ Description
|
|||||||
|
|
||||||
.. BEGIN DESCRIPTION
|
.. BEGIN DESCRIPTION
|
||||||
|
|
||||||
``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.
|
``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. If ``-n`` or ``--no-empty`` is specified, empty strings are excluded from consideration (e.g. ``string join -n + a b "" c`` would expand to ``a+b+c`` not ``a+b++c``).
|
||||||
|
|
||||||
``string join0`` 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.
|
``string join0`` 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.
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ Synopsis
|
|||||||
|
|
||||||
string collect [-N | --no-trim-newlines] [STRING ...]
|
string collect [-N | --no-trim-newlines] [STRING ...]
|
||||||
string escape [-n | --no-quoted] [--style=] [STRING ...]
|
string escape [-n | --no-quoted] [--style=] [STRING ...]
|
||||||
string join [-q | --quiet] SEP [STRING ...]
|
string join [-q | --quiet] [-n | --no-empty] SEP [STRING ...]
|
||||||
string join0 [-q | --quiet] [STRING ...]
|
string join0 [-q | --quiet] [STRING ...]
|
||||||
string length [-q | --quiet] [STRING ...]
|
string length [-q | --quiet] [STRING ...]
|
||||||
string lower [-q | --quiet] [STRING ...]
|
string lower [-q | --quiet] [STRING ...]
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ complete -f -c string -n 'test (count (commandline -opc)) -ge 2; and string matc
|
|||||||
|
|
||||||
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a join
|
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a join
|
||||||
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a join0
|
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a join0
|
||||||
|
complete -f -c string -n 'test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] join' -s n -l no-empty -d "Empty strings excluded"
|
||||||
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a trim
|
complete -f -c string -n "test (count (commandline -opc)) -lt 2" -a trim
|
||||||
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] trim" -s l -l left -d "Trim only leading chars"
|
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] trim" -s l -l left -d "Trim only leading chars"
|
||||||
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] trim" -s r -l right -d "Trim only trailing chars"
|
complete -f -c string -n "test (count (commandline -opc)) -ge 2; and contains -- (commandline -opc)[2] trim" -s r -l right -d "Trim only trailing chars"
|
||||||
|
|||||||
@@ -741,6 +741,7 @@ static int string_join_maybe0(parser_t &parser, io_streams_t &streams, int argc,
|
|||||||
const wchar_t **argv, bool is_join0) {
|
const wchar_t **argv, bool is_join0) {
|
||||||
options_t opts;
|
options_t opts;
|
||||||
opts.quiet_valid = true;
|
opts.quiet_valid = true;
|
||||||
|
opts.no_empty_valid = true;
|
||||||
int optind;
|
int optind;
|
||||||
int retval = parse_opts(&opts, &optind, is_join0 ? 0 : 1, argc, argv, parser, streams);
|
int retval = parse_opts(&opts, &optind, is_join0 ? 0 : 1, argc, argv, parser, streams);
|
||||||
if (retval != STATUS_CMD_OK) return retval;
|
if (retval != STATUS_CMD_OK) return retval;
|
||||||
@@ -750,6 +751,8 @@ static int string_join_maybe0(parser_t &parser, io_streams_t &streams, int argc,
|
|||||||
arg_iterator_t aiter(argv, optind, streams);
|
arg_iterator_t aiter(argv, optind, streams);
|
||||||
while (const wcstring *arg = aiter.nextstr()) {
|
while (const wcstring *arg = aiter.nextstr()) {
|
||||||
if (!opts.quiet) {
|
if (!opts.quiet) {
|
||||||
|
if (opts.no_empty && arg->empty()) continue;
|
||||||
|
|
||||||
if (nargs > 0) {
|
if (nargs > 0) {
|
||||||
streams.out.append(sep);
|
streams.out.append(sep);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user