From 9c8b50cb8f88bcb3a85257a04f1afb498bee1956 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Wed, 15 Feb 2023 18:45:00 +0100 Subject: [PATCH] docs: Make some code lines shorter For code, we need to limit the length because it can't be reflowed automatically --- doc_src/fish_for_bash_users.rst | 3 ++- doc_src/language.rst | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/doc_src/fish_for_bash_users.rst b/doc_src/fish_for_bash_users.rst index 81aa12686..44ae4e8a0 100644 --- a/doc_src/fish_for_bash_users.rst +++ b/doc_src/fish_for_bash_users.rst @@ -60,7 +60,8 @@ And here is fish:: > set foo "bar baz" > printf '"%s"\n' $foo - # foo was set as one element, so it will be passed as one element, so this is one line + # foo was set as one element, + # so it will be passed as one element, so this is one line "bar baz" All variables are "arrays" (we use the term "lists"), and expanding a variable expands to all its elements, with each element as its own argument (like bash's ``"${var[@]}"``:: diff --git a/doc_src/language.rst b/doc_src/language.rst index 51862c6a3..4167a4b5c 100644 --- a/doc_src/language.rst +++ b/doc_src/language.rst @@ -1099,12 +1099,13 @@ Here is an example of local vs function-scoped variables:: set gnu "In the beginning there was nothing, which exploded" end - echo $pirate # This will not output anything, since the pirate was local + echo $pirate + # This will output the good Captain's speech + # since $captain had function-scope. echo $captain - # This will output the good Captain's speech since $captain had function-scope. + # This will output Sir Terry's wisdom. echo $gnu - # Will output Sir Terry's wisdom. end When a function calls another, local variables aren't visible:: @@ -1141,7 +1142,8 @@ If you want to override a variable for a single command, you can use "var=val" s Unlike other shells, fish will first set the variable and then perform other expansions on the line, so:: set foo banana - foo=gagaga echo $foo # prints gagaga, while in other shells it might print "banana" + foo=gagaga echo $foo + # prints gagaga, while in other shells it might print "banana" Multiple elements can be given in a :ref:`brace expansion`:: @@ -1318,10 +1320,14 @@ That covers the positional arguments, but commandline tools often get various op A more robust approach to option handling is :doc:`argparse `, which checks the defined options and puts them into various variables, leaving only the positional arguments in $argv. Here's a simple example:: function mybetterfunction - # We tell argparse about -h/--help and -s/--second - these are short and long forms of the same option. - # The "--" here is mandatory, it tells it from where to read the arguments. + # We tell argparse about -h/--help and -s/--second + # - these are short and long forms of the same option. + # The "--" here is mandatory, + # it tells it from where to read the arguments. argparse h/help s/second -- $argv - # exit if argparse failed because it found an option it didn't recognize - it will print an error + # exit if argparse failed because + # it found an option it didn't recognize + # - it will print an error or return # If -h or --help is given, we print a little help text and return @@ -1760,7 +1766,8 @@ Let's make up an example. This function will :ref:`glob ` the f # If there are more than 5 files if test (count $files) -gt 5 - # and both stdin (for reading input) and stdout (for writing the prompt) + # and both stdin (for reading input) + # and stdout (for writing the prompt) # are terminals and isatty stdin and isatty stdout