Skip to content

Commit c3626a3

Browse files
committed
builtin read: --tokenize-raw option
Users have tried to get a list of all tokens -- including operators -- using "commandline --tokens-raw". That one has been deprecated by cc2ca60 (commandline.rst: deprecate --tokens-raw option, 2025-05-05). Part of the reason is that the above command is broken for multi-line tokens. Let's support this use case in a way that's less ambiguous. Closes #11084
1 parent f3b27e8 commit c3626a3

File tree

12 files changed

+159
-37
lines changed

12 files changed

+159
-37
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Scripting improvements
4848
- The :doc:`psub <cmds/psub>` command now allows combining ``--suffix`` with ``--fifo`` (:issue:`11729`).
4949
- Builtin :doc:`argparse <cmds/argparse>` has seen many improvements, see :ref:`below <changelog-4.1-argparse>`.
5050
- The :doc:`string pad <cmds/string-pad>` command now has a ``-C/--center`` option.
51+
- The :doc:`read <cmds/read>` builtin has learned the ``--tokenize-raw`` option to tokenize without quote removal (:issue:`11084`).
5152

5253
Interactive improvements
5354
------------------------

doc_src/cmds/read.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ The following options control how much is read and how it is stored:
8383
**-n** or **--nchars** *NCHARS*
8484
Makes ``read`` return after reading *NCHARS* characters or the end of the line, whichever comes first.
8585

86-
**-t** -or **--tokenize**
87-
Causes read to split the input into variables by the shell's tokenization rules. This means it will honor quotes and escaping. This option is of course incompatible with other options to control splitting like **--delimiter** and does not honor :envvar:`IFS` (like fish's tokenizer). It saves the tokens in the manner they'd be passed to commands on the commandline, so e.g. ``a\ b`` is stored as ``a b``. Note that currently it leaves command substitutions intact along with the parentheses.
86+
**-t**, **--tokenize** or **--tokenize-raw**
87+
Causes read to split the input into variables by the shell's tokenization rules.
88+
This means it will honor quotes and escaping.
89+
This option is of course incompatible with other options to control splitting like **--delimiter** and does not honor :envvar:`IFS` (like fish's tokenizer).
90+
The **-t** -or **--tokenize** variants perform quote removal, so e.g. ``a\ b`` is stored as ``a b``.
91+
However variables and command substitutions are not expanded.
8892

8993
**-a** or **--list**
9094
Stores the result as a list in a single variable. This option is also available as **--array** for backwards compatibility.

po/de.po

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,11 @@ msgstr ""
811811
msgid "%s"
812812
msgstr ""
813813

814+
#
815+
#, c-format
816+
msgid "%s and %s are mutually exclusive"
817+
msgstr ""
818+
814819
#, c-format
815820
msgid "%s, version %s"
816821
msgstr ""

po/en.po

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,11 @@ msgstr ""
809809
msgid "%s"
810810
msgstr ""
811811

812+
#
813+
#, c-format
814+
msgid "%s and %s are mutually exclusive"
815+
msgstr ""
816+
812817
#, c-format
813818
msgid "%s, version %s"
814819
msgstr ""

po/fr.po

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,11 @@ msgstr ""
910910
msgid "%s"
911911
msgstr ""
912912

913+
#
914+
#, c-format
915+
msgid "%s and %s are mutually exclusive"
916+
msgstr ""
917+
913918
#, c-format
914919
msgid "%s, version %s"
915920
msgstr ""

po/pl.po

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,11 @@ msgstr ""
805805
msgid "%s"
806806
msgstr ""
807807

808+
#
809+
#, c-format
810+
msgid "%s and %s are mutually exclusive"
811+
msgstr ""
812+
808813
#, c-format
809814
msgid "%s, version %s"
810815
msgstr ""

po/pt_BR.po

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,11 @@ msgstr ""
810810
msgid "%s"
811811
msgstr ""
812812

813+
#
814+
#, c-format
815+
msgid "%s and %s are mutually exclusive"
816+
msgstr ""
817+
813818
#, c-format
814819
msgid "%s, version %s"
815820
msgstr ""

po/sv.po

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,11 @@ msgstr ""
806806
msgid "%s"
807807
msgstr ""
808808

809+
#
810+
#, c-format
811+
msgid "%s and %s are mutually exclusive"
812+
msgstr ""
813+
809814
#, c-format
810815
msgid "%s, version %s"
811816
msgstr ""

po/zh_CN.po

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,11 @@ msgstr "%lu\n"
803803
msgid "%s"
804804
msgstr ""
805805

806+
#
807+
#, c-format
808+
msgid "%s and %s are mutually exclusive"
809+
msgstr ""
810+
806811
#, c-format
807812
msgid "%s, version %s"
808813
msgstr ""

src/builtins/commandline.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::prelude::*;
2+
use super::read::TokenOutputMode;
23
use crate::ast::{self, Kind, Leaf};
34
use crate::common::{unescape_string, UnescapeFlags, UnescapeStringStyle};
45
use crate::complete::Completion;
@@ -44,12 +45,6 @@ enum AppendMode {
4445
Append,
4546
}
4647

47-
enum TokenOutputMode {
48-
Expanded,
49-
Raw,
50-
Unescaped,
51-
}
52-
5348
/// Replace/append/insert the selection with/at/after the specified string.
5449
///
5550
/// \param begin beginning of selection

0 commit comments

Comments
 (0)