From 38cadc9d4f9cd7466713d66729d78e7227c5dc07 Mon Sep 17 00:00:00 2001 From: David Gowers Date: Fri, 26 Apr 2019 23:00:13 +0930 Subject: [PATCH] Variables as commands are in fact supported, eval docs should not claim otherwise. (#5819) Provide an example that somewhat justifies eval's existence in light of this change. Also correct similar misinformation found in a comment. --- sphinx_doc_src/cmds/eval.rst | 9 +++++---- src/complete.cpp | 4 +--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/sphinx_doc_src/cmds/eval.rst b/sphinx_doc_src/cmds/eval.rst index e3d7d8e5e..b59fb5b14 100644 --- a/sphinx_doc_src/cmds/eval.rst +++ b/sphinx_doc_src/cmds/eval.rst @@ -15,16 +15,17 @@ Description If your command does not need access to stdin, consider using ``source`` instead. +If no piping or other compound shell constructs are required, variable-expansion-as-command, as in ``set cmd ls; $cmd``, is also an option. + + Example ------- -The following code will call the ls command. Note that ``fish`` does not support the use of shell variables as direct commands; ``eval`` can be used to work around this. - - +The following code will call the ls command and truncate each filename to the first 12 characters. :: - set cmd ls + set cmd ls \| cut -c 1-12 eval $cmd diff --git a/src/complete.cpp b/src/complete.cpp index 4cb981eb2..8ce6d3079 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -1378,9 +1378,7 @@ void completer_t::perform() { // If we are completing a variable name or a tilde expansion user name, we do that and return. // No need for any other completions. - // Unconditionally complete variables and processes. This is a little weird since we will - // happily complete variables even in e.g. command position, despite the fact that they are - // invalid there. */ + // Unconditionally complete variables and processes. const wcstring current_token = tok_begin; if (try_complete_variable(current_token) || try_complete_user(current_token)) { return;