From 50a40175f1aa4a2681be835c106a9f66fa51eb9a Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 24 Jul 2020 17:17:39 +0200 Subject: [PATCH] docs: More on conditionals directly It's weird to force people to go to the separate pages, at least give some simple examples here and link to the tutorial. [ci skip] --- doc_src/index.rst | 17 +++++++++++++++-- doc_src/tutorial.rst | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc_src/index.rst b/doc_src/index.rst index d46dfdf1a..dba3976e8 100644 --- a/doc_src/index.rst +++ b/doc_src/index.rst @@ -472,13 +472,26 @@ After entering ``gco`` and pressing :kbd:`Space` or :kbd:`Enter`, the full text Conditional execution of code and flow control ---------------------------------------------- -There are four fish builtins that let you execute commands only if a specific criterion is met. These builtins are :ref:`if `, :ref:`switch `, :ref:`and ` and :ref:`or `. +Fish has some builtins that let you execute commands only if a specific criterion is met: :ref:`if `, :ref:`switch `, :ref:`and ` and :ref:`or `, and also the familiar :ref:`&&/|| ` syntax. The :ref:`switch ` command is used to execute one of possibly many blocks of commands depending on the value of a string. See the documentation for :ref:`switch ` for more information. -The other conditionals use the `exit status <#variables-status>`_ of a command to decide if a command or a block of commands should be executed. See their documentation for more information. +The other conditionals use the `exit status <#variables-status>`_ of a command to decide if a command or a block of commands should be executed. +Some examples:: + # Just see if the file contains the string "fish" anywhere. + if grep -q fish myanimals + echo You have fish! + else + echo You don't have fish! + end + + # $XDG_CONFIG_HOME is a standard place to store configuration. If it's not set applications should use ~/.config. + set -q XDG_CONFIG_HOME; and set -l configdir $XDG_CONFIG_HOME + or set -l configdir ~/.config + +For more, see the documentation for the builtins or the :ref:`Conditionals ` section of the tutorial. .. _expand: diff --git a/doc_src/tutorial.rst b/doc_src/tutorial.rst index 898cec95b..31f8cb7a9 100644 --- a/doc_src/tutorial.rst +++ b/doc_src/tutorial.rst @@ -440,6 +440,7 @@ As mentioned in :ref:`the section on the semicolon `, this can al and echo "Backup successful" or echo "Backup failed" +.. _tut-conditionals: Conditionals (If, Else, Switch) -------------------------------