Switch \fish sections to rst format

This commit is contained in:
ridiculousfish 2018-12-18 19:14:04 -08:00
parent c33d1a217c
commit 2a002a4ba1
53 changed files with 993 additions and 693 deletions

View file

@ -42,29 +42,44 @@ See the "Internals" section for more on them.
Examples Examples
------------ ------------
\fish
abbr -a -g gco git checkout
\endfish ::
abbr -a -g gco git checkout
Add a new abbreviation where `gco` will be replaced with `git checkout` global to the current shell. This abbreviation will not be automatically visible to other shells unless the same command is run in those shells (such as when executing the commands in config.fish). Add a new abbreviation where `gco` will be replaced with `git checkout` global to the current shell. This abbreviation will not be automatically visible to other shells unless the same command is run in those shells (such as when executing the commands in config.fish).
\fish
abbr -a -U l less
\endfish ::
abbr -a -U l less
Add a new abbreviation where `l` will be replaced with `less` universal so all shells. Note that you omit the `-U` since it is the default. Add a new abbreviation where `l` will be replaced with `less` universal so all shells. Note that you omit the `-U` since it is the default.
\fish
abbr -r gco gch
\endfish ::
abbr -r gco gch
Renames an existing abbreviation from `gco` to `gch`. Renames an existing abbreviation from `gco` to `gch`.
\fish
abbr -e gco
\endfish ::
abbr -e gco
Erase the `gco` abbreviation. Erase the `gco` abbreviation.
\fish
ssh another_host abbr -s | source
\endfish ::
ssh another_host abbr -s | source
Import the abbreviations defined on another_host over SSH. Import the abbreviations defined on another_host over SSH.
Internals Internals
@ -73,13 +88,16 @@ Each abbreviation is stored in its own global or universal variable. The name co
Defining an abbreviation with global scope is slightly faster than universal scope (which is the default). But in general you'll only want to use the global scope when defining abbreviations in a startup script like `~/.config/fish/config.fish` like this: Defining an abbreviation with global scope is slightly faster than universal scope (which is the default). But in general you'll only want to use the global scope when defining abbreviations in a startup script like `~/.config/fish/config.fish` like this:
\fish
if status --is-interactive
abbr --add --global first 'echo my first abbreviation' ::
abbr --add --global second 'echo my second abbreviation'
abbr --add --global gco git checkout if status --is-interactive
# etcetera abbr --add --global first 'echo my first abbreviation'
end abbr --add --global second 'echo my second abbreviation'
\endfish abbr --add --global gco git checkout
# etcetera
end
You can create abbreviations interactively and they will be visible to other fish sessions if you use the `-U` or `--universal` flag or don't explicitly specify the scope and the abbreviation isn't already defined with global scope. If you want it to be visible only to the current shell use the `-g` or `--global` flag. You can create abbreviations interactively and they will be visible to other fish sessions if you use the `-U` or `--universal` flag or don't explicitly specify the scope and the abbreviation isn't already defined with global scope. If you want it to be visible only to the current shell use the `-g` or `--global` flag.

View file

@ -32,14 +32,17 @@ Example
The following code will create `rmi`, which runs `rm` with additional arguments on every invocation. The following code will create `rmi`, which runs `rm` with additional arguments on every invocation.
\fish
alias rmi="rm -i"
# This is equivalent to entering the following function:
function rmi --wraps rm --description 'alias rmi=rm -i'
rm -i $argv
end
# This needs to have the spaces escaped or "Chrome.app..." will be seen as an argument to "/Applications/Google": ::
alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome banana'
\endfish alias rmi="rm -i"
# This is equivalent to entering the following function:
function rmi --wraps rm --description 'alias rmi=rm -i'
rm -i $argv
end
# This needs to have the spaces escaped or "Chrome.app..." will be seen as an argument to "/Applications/Google":
alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome banana'

View file

@ -21,7 +21,10 @@ Example
The following code runs the `make` command to build a program. If the build succeeds, `make`'s exit status is 0, and the program is installed. If either step fails, the exit status is 1, and `make clean` is run, which removes the files created by the build process. The following code runs the `make` command to build a program. If the build succeeds, `make`'s exit status is 0, and the program is installed. If either step fails, the exit status is 1, and `make clean` is run, which removes the files created by the build process.
\fish
make; and make install; or make clean
\endfish ::
make; and make install; or make clean

View file

@ -40,26 +40,35 @@ Usage
Using this command involves passing two sets of arguments separated by `--`. The first set consists of one or more option specifications (`OPTION_SPEC` above) and options that modify the behavior of `argparse`. These must be listed before the `--` argument. The second set are the arguments to be parsed in accordance with the option specifications. They occur after the `--` argument and can be empty. More about this below but here is a simple example that might be used in a function named `my_function`: Using this command involves passing two sets of arguments separated by `--`. The first set consists of one or more option specifications (`OPTION_SPEC` above) and options that modify the behavior of `argparse`. These must be listed before the `--` argument. The second set are the arguments to be parsed in accordance with the option specifications. They occur after the `--` argument and can be empty. More about this below but here is a simple example that might be used in a function named `my_function`:
\fish
argparse --name=my_function 'h/help' 'n/name=' -- $argv
or return ::
\endfish
argparse --name=my_function 'h/help' 'n/name=' -- $argv
or return
If `$argv` is empty then there is nothing to parse and `argparse` returns zero to indicate success. If `$argv` is not empty then it is checked for flags `-h`, `--help`, `-n` and `--name`. If they are found they are removed from the arguments and local variables (more on this <a href="argparse-local-variables">below</a>) are set so the script can determine which options were seen. Assuming `$argv` doesn't have any errors, such as a missing mandatory value for an option, then `argparse` exits with status zero. Otherwise it writes appropriate error messages to stderr and exits with a status of one. If `$argv` is empty then there is nothing to parse and `argparse` returns zero to indicate success. If `$argv` is not empty then it is checked for flags `-h`, `--help`, `-n` and `--name`. If they are found they are removed from the arguments and local variables (more on this <a href="argparse-local-variables">below</a>) are set so the script can determine which options were seen. Assuming `$argv` doesn't have any errors, such as a missing mandatory value for an option, then `argparse` exits with status zero. Otherwise it writes appropriate error messages to stderr and exits with a status of one.
The `--` argument is required. You do not have to include any arguments after the `--` but you must include the `--`. For example, this is acceptable: The `--` argument is required. You do not have to include any arguments after the `--` but you must include the `--`. For example, this is acceptable:
\fish
set -l argv
argparse 'h/help' 'n/name' -- $argv ::
\endfish
set -l argv
argparse 'h/help' 'n/name' -- $argv
But this is not: But this is not:
\fish
set -l argv
argparse 'h/help' 'n/name' $argv ::
\endfish
set -l argv
argparse 'h/help' 'n/name' $argv
The first `--` seen is what allows the `argparse` command to reliably separate the option specifications from the command arguments. The first `--` seen is what allows the `argparse` command to reliably separate the option specifications from the command arguments.

View file

@ -24,27 +24,33 @@ Example
The following code sets a number of variables inside of a block scope. Since the variables are set inside the block and have local scope, they will be automatically deleted when the block ends. The following code sets a number of variables inside of a block scope. Since the variables are set inside the block and have local scope, they will be automatically deleted when the block ends.
\fish
begin
set -l PIRATE Yarrr
...
end
echo $PIRATE ::
# This will not output anything, since the PIRATE variable
# went out of scope at the end of the block begin
\endfish set -l PIRATE Yarrr
...
end
echo $PIRATE
# This will not output anything, since the PIRATE variable
# went out of scope at the end of the block
In the following code, all output is redirected to the file out.html. In the following code, all output is redirected to the file out.html.
\fish
begin
echo $xml_header ::
echo $html_header
if test -e $file begin
echo $xml_header
echo $html_header
if test -e $file
...
end
... ...
end end > out.html
...
end > out.html
\endfish

View file

@ -149,20 +149,29 @@ The following special input functions are available:
Examples Examples
------------ ------------
\fish
bind <asis>\\cd</asis> 'exit'
\endfish ::
bind <asis>\\cd</asis> 'exit'
Causes `fish` to exit when @key{Control,D} is pressed. Causes `fish` to exit when @key{Control,D} is pressed.
\fish
bind -k ppage history-search-backward
\endfish ::
bind -k ppage history-search-backward
Performs a history search when the @key{Page Up} key is pressed. Performs a history search when the @key{Page Up} key is pressed.
\fish
set -g fish_key_bindings fish_vi_key_bindings
bind -M insert \\cc kill-whole-line force-repaint ::
\endfish
set -g fish_key_bindings fish_vi_key_bindings
bind -M insert \\cc kill-whole-line force-repaint
Turns on Vi key bindings and rebinds @key{Control,C} to clear the input line. Turns on Vi key bindings and rebinds @key{Control,C} to clear the input line.

View file

@ -30,19 +30,22 @@ The following parameters are available:
Example Example
------------ ------------
\fish
# Create a function that listens for events
function --on-event foo foo; echo 'foo fired'; end
# Block the delivery of events
block -g
emit foo ::
# No output will be produced
# Create a function that listens for events
function --on-event foo foo; echo 'foo fired'; end
# Block the delivery of events
block -g
emit foo
# No output will be produced
block -e
# 'foo fired' will now be printed
block -e
# 'foo fired' will now be printed
\endfish
Notes Notes

View file

@ -19,11 +19,14 @@ Example
------------ ------------
The following code searches all .c files for "smurf", and halts at the first occurrence. The following code searches all .c files for "smurf", and halts at the first occurrence.
\fish
for i in *.c
if grep smurf $i ::
echo Smurfs are present in $i
break for i in *.c
if grep smurf $i
echo Smurfs are present in $i
break
end
end end
end
\endfish

View file

@ -20,7 +20,10 @@ The following parameters are available:
Example Example
------------ ------------
\fish
builtin jobs
# executes the jobs builtin, even if a function named jobs exists ::
\endfish
builtin jobs
# executes the jobs builtin, even if a function named jobs exists

View file

@ -24,21 +24,24 @@ Example
Say \$animal contains the name of an animal. Then this code would classify it: Say \$animal contains the name of an animal. Then this code would classify it:
\fish
switch $animal
case cat ::
echo evil
case wolf dog human moose dolphin whale switch $animal
echo mammal case cat
case duck goose albatross echo evil
echo bird case wolf dog human moose dolphin whale
case shark trout stingray echo mammal
echo fish case duck goose albatross
# Note that the next case has a wildcard which is quoted echo bird
case '*' case shark trout stingray
echo I have no idea what a $animal is echo fish
end # Note that the next case has a wildcard which is quoted
\endfish case '*'
echo I have no idea what a $animal is
end
If the above code was run with `$animal` set to `whale`, the output If the above code was run with `$animal` set to `whale`, the output
would be `mammal`. would be `mammal`.

View file

@ -24,13 +24,16 @@ As a special case, `cd .` is equivalent to `cd $PWD`, which is useful in cases w
Examples Examples
------------ ------------
\fish
cd
# changes the working directory to your home directory.
cd /usr/src/fish-shell
# changes the working directory to /usr/src/fish-shell ::
\endfish
cd
# changes the working directory to your home directory.
cd /usr/src/fish-shell
# changes the working directory to /usr/src/fish-shell
See Also See Also
------------ ------------

View file

@ -65,22 +65,28 @@ Example
`commandline -j $history[3]` replaces the job under the cursor with the third item from the command line history. `commandline -j $history[3]` replaces the job under the cursor with the third item from the command line history.
If the commandline contains If the commandline contains
\fish
>_ echo $fl___ounder >&2 | less; and echo $catfish
\endfish ::
>_ echo $fl___ounder >&2 | less; and echo $catfish
(with the cursor on the "o" of "flounder") (with the cursor on the "o" of "flounder")
Then the following invocations behave like this: Then the following invocations behave like this:
\fish
>_ commandline -t
$flounder ::
>_ commandline -ct
$fl >_ commandline -t
>_ commandline -b # or just commandline $flounder
echo $flounder >&2 | less; and echo $catfish >_ commandline -ct
>_ commandline -p $fl
echo $flounder >&2 >_ commandline -b # or just commandline
>_ commandline -j echo $flounder >&2 | less; and echo $catfish
echo $flounder >&2 | less >_ commandline -p
\endfish echo $flounder >&2
>_ commandline -j
echo $flounder >&2 | less

View file

@ -99,37 +99,52 @@ Example
The short style option `-o` for the `gcc` command requires that a file follows it. This can be done using writing: The short style option `-o` for the `gcc` command requires that a file follows it. This can be done using writing:
\fish
complete -c gcc -s o -r
\endfish ::
complete -c gcc -s o -r
The short style option `-d` for the `grep` command requires that one of the strings '`read`', '`skip`' or '`recurse`' is used. This can be specified writing: The short style option `-d` for the `grep` command requires that one of the strings '`read`', '`skip`' or '`recurse`' is used. This can be specified writing:
\fish
complete -c grep -s d -x -a "read skip recurse"
\endfish ::
complete -c grep -s d -x -a "read skip recurse"
The `su` command takes any username as an argument. Usernames are given as the first colon-separated field in the file /etc/passwd. This can be specified as: The `su` command takes any username as an argument. Usernames are given as the first colon-separated field in the file /etc/passwd. This can be specified as:
\fish
complete -x -c su -d "Username" -a "(cat /etc/passwd | cut -d : -f 1)"
\endfish ::
complete -x -c su -d "Username" -a "(cat /etc/passwd | cut -d : -f 1)"
The `rpm` command has several different modes. If the `-e` or `--erase` flag has been specified, `rpm` should delete one or more packages, in which case several switches related to deleting packages are valid, like the `nodeps` switch. The `rpm` command has several different modes. If the `-e` or `--erase` flag has been specified, `rpm` should delete one or more packages, in which case several switches related to deleting packages are valid, like the `nodeps` switch.
This can be written as: This can be written as:
\fish
complete -c rpm -n "__fish_contains_opt -s e erase" -l nodeps -d "Don't check dependencies"
\endfish ::
complete -c rpm -n "__fish_contains_opt -s e erase" -l nodeps -d "Don't check dependencies"
where `__fish_contains_opt` is a function that checks the command line buffer for the presence of a specified set of options. where `__fish_contains_opt` is a function that checks the command line buffer for the presence of a specified set of options.
To implement an alias, use the `-w` or `--wraps` option: To implement an alias, use the `-w` or `--wraps` option:
\fish
complete -c hub -w git
\endfish ::
complete -c hub -w git
Now hub inherits all of the completions from git. Note this can also be specified in a function declaration. Now hub inherits all of the completions from git. Note this can also be specified in a function declaration.

View file

@ -23,30 +23,39 @@ Example
If $animals is a list of animals, the following will test if it contains a cat: If $animals is a list of animals, the following will test if it contains a cat:
\fish
if contains cat $animals
echo Your animal list is evil! ::
end
\endfish if contains cat $animals
echo Your animal list is evil!
end
This code will add some directories to $PATH if they aren't yet included: This code will add some directories to $PATH if they aren't yet included:
\fish
for i in ~/bin /usr/local/bin
if not contains $i $PATH ::
set PATH $PATH $i
for i in ~/bin /usr/local/bin
if not contains $i $PATH
set PATH $PATH $i
end
end end
end
\endfish
While this will check if `hasargs` was run with the `-q` option: While this will check if `hasargs` was run with the `-q` option:
\fish
function hasargs
if contains -- -q $argv ::
echo '$argv contains a -q option'
function hasargs
if contains -- -q $argv
echo '$argv contains a -q option'
end
end end
end
\endfish
The `--` here stops `contains` from treating `-q` to an option to itself. Instead it treats it as a normal string to check. The `--` here stops `contains` from treating `-q` to an option to itself. Instead it treats it as a normal string to check.

View file

@ -17,14 +17,17 @@ Example
The following code removes all tmp files that do not contain the word smurf. The following code removes all tmp files that do not contain the word smurf.
\fish
for i in *.tmp
if grep smurf $i ::
continue
for i in *.tmp
if grep smurf $i
continue
end
# This "rm" is skipped over if "continue" is executed.
rm $i
# As is this "echo"
echo $i
end end
# This "rm" is skipped over if "continue" is executed.
rm $i
# As is this "echo"
echo $i
end
\endfish

View file

@ -20,10 +20,13 @@ Description
Example Example
------------ ------------
\fish
count $PATH
# Returns the number of directories in the users PATH variable.
count *.txt
# Returns the number of files in the current working directory ending with the suffix '.txt'. ::
\endfish
count $PATH
# Returns the number of directories in the users PATH variable.
count *.txt
# Returns the number of files in the current working directory ending with the suffix '.txt'.

View file

@ -54,12 +54,18 @@ If `-e` is used, the following sequences are recognized:
Example Example
------------ ------------
\fish
echo 'Hello World'
\endfish ::
echo 'Hello World'
Print hello world to stdout Print hello world to stdout
\fish
echo -e 'Top\\nBottom'
\endfish ::
echo -e 'Top\\nBottom'
Print Top and Bottom on separate lines, using an escape sequence Print Top and Bottom on separate lines, using an escape sequence

View file

@ -18,10 +18,13 @@ Example
The following code tests whether a file `foo.txt` exists as a regular file. The following code tests whether a file `foo.txt` exists as a regular file.
\fish
if test -f foo.txt
echo foo.txt exists ::
else
echo foo.txt does not exist if test -f foo.txt
end echo foo.txt exists
\endfish else
echo foo.txt does not exist
end

View file

@ -18,13 +18,16 @@ Example
The following code first defines an event handler for the generic event named 'test_event', and then emits an event of that type. The following code first defines an event handler for the generic event named 'test_event', and then emits an event of that type.
\fish
function event_test --on-event test_event
echo event test: $argv
end
emit test_event something
\endfish ::
function event_test --on-event test_event
echo event test: $argv
end
emit test_event something
Notes Notes

View file

@ -18,8 +18,11 @@ 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. Note that `fish` does not support the use of shell variables as direct commands; `eval` can be used to work around this.
\fish
set cmd ls
eval $cmd ::
\endfish
set cmd ls
eval $cmd

View file

@ -24,11 +24,14 @@ Example
A simple prompt that is a simplified version of the default debugging prompt: A simple prompt that is a simplified version of the default debugging prompt:
\fish
function fish_breakpoint_prompt -d "Write out the debug prompt"
set -l function (status current-function) ::
set -l line (status current-line-number)
set -l prompt "$function:$line >" function fish_breakpoint_prompt -d "Write out the debug prompt"
echo -ns (set_color $fish_color_status) "BP $prompt" (set_color normal) ' ' set -l function (status current-function)
end set -l line (status current-line-number)
\endfish set -l prompt "$function:$line >"
echo -ns (set_color $fish_color_status) "BP $prompt" (set_color normal) ' '
end

View file

@ -14,27 +14,30 @@ will be one of `default`, `insert`, `replace_one`, or `visual`.
Example Example
------------ ------------
\fish
function fish_mode_prompt
switch $fish_bind_mode ::
case default
set_color --bold red function fish_mode_prompt
echo 'N' switch $fish_bind_mode
case insert case default
set_color --bold green set_color --bold red
echo 'I' echo 'N'
case replace_one case insert
set_color --bold green set_color --bold green
echo 'R' echo 'I'
case visual case replace_one
set_color --bold brmagenta set_color --bold green
echo 'V' echo 'R'
case '*' case visual
set_color --bold red set_color --bold brmagenta
echo '?' echo 'V'
end case '*'
set_color normal set_color --bold red
end echo '?'
\endfish end
set_color normal
end
Outputting multiple lines is not supported in `fish_mode_prompt`. Outputting multiple lines is not supported in `fish_mode_prompt`.

View file

@ -35,24 +35,33 @@ Examples
Define a single option spec for the boolean help flag: Define a single option spec for the boolean help flag:
\fish
set -l options (fish_opt -s h -l help)
argparse $options -- $argv ::
\endfish
set -l options (fish_opt -s h -l help)
argparse $options -- $argv
Same as above but with a second flag that requires a value: Same as above but with a second flag that requires a value:
\fish
set -l options (fish_opt -s h -l help)
set options $options (fish_opt -s m -l max --required-val) ::
argparse $options -- $argv
\endfish set -l options (fish_opt -s h -l help)
set options $options (fish_opt -s m -l max --required-val)
argparse $options -- $argv
Same as above but with a third flag that can be given multiple times saving the value of each instance seen and only the long flag name (`--token`) can be used: Same as above but with a third flag that can be given multiple times saving the value of each instance seen and only the long flag name (`--token`) can be used:
\fish
set -l options (fish_opt --short=h --long=help)
set options $options (fish_opt --short=m --long=max --required-val) ::
set options $options (fish_opt --short=t --long=token --multiple-vals --long-only)
argparse $options -- $argv set -l options (fish_opt --short=h --long=help)
\endfish set options $options (fish_opt --short=m --long=max --required-val)
set options $options (fish_opt --short=t --long=token --multiple-vals --long-only)
argparse $options -- $argv

View file

@ -24,10 +24,13 @@ Example
A simple prompt: A simple prompt:
\fish
function fish_prompt -d "Write out the prompt"
printf '%s@%s%s%s%s> ' (whoami) (hostname | cut -d . -f 1) \ ::
(set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
end function fish_prompt -d "Write out the prompt"
\endfish printf '%s@%s%s%s%s> ' (whoami) (hostname | cut -d . -f 1) \
(set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
end

View file

@ -22,9 +22,12 @@ Example
A simple right prompt: A simple right prompt:
\fish
function fish_right_prompt -d "Write out the right prompt"
date '+%m/%d/%y' ::
end
\endfish function fish_right_prompt -d "Write out the right prompt"
date '+%m/%d/%y'
end

View file

@ -15,27 +15,33 @@ Description
Example Example
------------ ------------
\fish
for i in foo bar baz; echo $i; end
# would output:
foo ::
bar
baz for i in foo bar baz; echo $i; end
\endfish
# would output:
foo
bar
baz
Notes Notes
------------ ------------
The `VARNAME` was local to the for block in releases prior to 3.0.0. This means that if you did something like this: The `VARNAME` was local to the for block in releases prior to 3.0.0. This means that if you did something like this:
\fish
for var in a b c
if break_from_loop ::
break
for var in a b c
if break_from_loop
break
end
end end
end echo $var
echo $var
\endfish
The last value assigned to `var` when the loop terminated would not be available outside the loop. What `echo $var` would write depended on what it was set to before the loop was run. Likely nothing. The last value assigned to `var` when the loop terminated would not be available outside the loop. What `echo $var` would write depended on what it was set to before the loop was run. Likely nothing.

View file

@ -60,42 +60,51 @@ By using one of the event handler switches, a function can be made to run automa
Example Example
------------ ------------
\fish
function ll
ls -l $argv ::
end
\endfish function ll
ls -l $argv
end
will run the `ls` command, using the `-l` option, while passing on any additional files and switches to `ls`. will run the `ls` command, using the `-l` option, while passing on any additional files and switches to `ls`.
\fish
function mkdir -d "Create a directory and set CWD"
command mkdir $argv
if test $status = 0
switch $argv[(count $argv)]
case '-*'
case '*'
cd $argv[(count $argv)] ::
return
function mkdir -d "Create a directory and set CWD"
command mkdir $argv
if test $status = 0
switch $argv[(count $argv)]
case '-*'
case '*'
cd $argv[(count $argv)]
return
end
end end
end end
end
\endfish
This will run the `mkdir` command, and if it is successful, change the current working directory to the one just created. This will run the `mkdir` command, and if it is successful, change the current working directory to the one just created.
\fish
function notify
set -l job (jobs -l -g)
or begin; echo "There are no jobs" >&2; return 1; end
function _notify_job_$job --on-job-exit $job --inherit-variable job
echo -n \a # beep ::
functions -e _notify_job_$job
function notify
set -l job (jobs -l -g)
or begin; echo "There are no jobs" >&2; return 1; end
function _notify_job_$job --on-job-exit $job --inherit-variable job
echo -n \a # beep
functions -e _notify_job_$job
end
end end
end
\endfish
This will beep when the most recent job completes. This will beep when the most recent job completes.

View file

@ -61,13 +61,16 @@ The exit status of `functions` is the number of functions specified in the argum
Examples Examples
------------ ------------
\fish
functions -n
# Displays a list of currently-defined functions
functions -c foo bar
# Copies the 'foo' function to a new function called 'bar'
functions -e bar ::
# Erases the function `bar`
\endfish functions -n
# Displays a list of currently-defined functions
functions -c foo bar
# Copies the 'foo' function to a new function called 'bar'
functions -e bar
# Erases the function `bar`

View file

@ -54,17 +54,20 @@ These flags can appear before or immediately after one of the sub-commands liste
Example Example
------------ ------------
\fish
history clear
# Deletes all history items
history search --contains "foo"
# Outputs a list of all previous commands containing the string "foo".
history delete --prefix "foo" ::
# Interactively deletes commands which start with "foo" from the history.
# You can select more than one entry by entering their IDs separated by a space. history clear
\endfish # Deletes all history items
history search --contains "foo"
# Outputs a list of all previous commands containing the string "foo".
history delete --prefix "foo"
# Interactively deletes commands which start with "foo" from the history.
# You can select more than one entry by entering their IDs separated by a space.
Customizing the name of the history file Customizing the name of the history file
------------ ------------

View file

@ -24,20 +24,26 @@ Example
The following code will print `foo.txt exists` if the file foo.txt exists and is a regular file, otherwise it will print `bar.txt exists` if the file bar.txt exists and is a regular file, otherwise it will print `foo.txt and bar.txt do not exist`. The following code will print `foo.txt exists` if the file foo.txt exists and is a regular file, otherwise it will print `bar.txt exists` if the file bar.txt exists and is a regular file, otherwise it will print `foo.txt and bar.txt do not exist`.
\fish
if test -f foo.txt
echo foo.txt exists ::
else if test -f bar.txt
echo bar.txt exists if test -f foo.txt
else echo foo.txt exists
echo foo.txt and bar.txt do not exist else if test -f bar.txt
end echo bar.txt exists
\endfish else
echo foo.txt and bar.txt do not exist
end
The following code will print "foo.txt exists and is readable" if foo.txt is a regular file and readable The following code will print "foo.txt exists and is readable" if foo.txt is a regular file and readable
\fish
if test -f foo.txt
and test -r foo.txt ::
echo "foo.txt exists and is readable"
end if test -f foo.txt
\endfish and test -r foo.txt
echo "foo.txt exists and is readable"
end

View file

@ -22,18 +22,24 @@ Examples
From an interactive shell, the commands below exit with a return value of zero: From an interactive shell, the commands below exit with a return value of zero:
\fish
isatty
isatty stdout ::
isatty 2
echo | isatty 1 isatty
\endfish isatty stdout
isatty 2
echo | isatty 1
And these will exit non-zero: And these will exit non-zero:
\fish
echo | isatty
isatty 9 ::
isatty stdout > file
isatty 2 2> file echo | isatty
\endfish isatty 9
isatty stdout > file
isatty 2 2> file

View file

@ -21,16 +21,19 @@ You may be interested in the <a href="commands.html#cdh">`cdh`</a> command which
Example Example
------------ ------------
\fish
cd /usr/src
# Working directory is now /usr/src
cd /usr/src/fish-shell
# Working directory is now /usr/src/fish-shell
prevd ::
# Working directory is now /usr/src
cd /usr/src
# Working directory is now /usr/src
cd /usr/src/fish-shell
# Working directory is now /usr/src/fish-shell
prevd
# Working directory is now /usr/src
nextd
# Working directory is now /usr/src/fish-shell
nextd
# Working directory is now /usr/src/fish-shell
\endfish

View file

@ -18,10 +18,13 @@ Example
The following code reports an error and exits if no file named spoon can be found. The following code reports an error and exits if no file named spoon can be found.
\fish
if not test -f spoon
echo There is no spoon ::
exit 1
end if not test -f spoon
\endfish echo There is no spoon
exit 1
end

View file

@ -22,6 +22,9 @@ Example
The following code runs the `make` command to build a program. If the build succeeds, the program is installed. If either step fails, `make clean` is run, which removes the files created by the build process. The following code runs the `make` command to build a program. If the build succeeds, the program is installed. If either step fails, `make clean` is run, which removes the files created by the build process.
\fish
make; and make install; or make clean
\endfish ::
make; and make install; or make clean

View file

@ -17,16 +17,19 @@ You may be interested in the <a href="commands.html#cdh">`cdh`</a> command which
Example Example
------------ ------------
\fish
pushd /usr/src
# Working directory is now /usr/src
# Directory stack contains /usr/src
pushd /usr/src/fish-shell
# Working directory is now /usr/src/fish-shell
# Directory stack contains /usr/src /usr/src/fish-shell
popd ::
# Working directory is now /usr/src
# Directory stack contains /usr/src pushd /usr/src
\endfish # Working directory is now /usr/src
# Directory stack contains /usr/src
pushd /usr/src/fish-shell
# Working directory is now /usr/src/fish-shell
# Directory stack contains /usr/src /usr/src/fish-shell
popd
# Working directory is now /usr/src
# Directory stack contains /usr/src

View file

@ -21,16 +21,19 @@ You may be interested in the <a href="commands.html#cdh">`cdh`</a> command which
Example Example
------------ ------------
\fish
cd /usr/src
# Working directory is now /usr/src
cd /usr/src/fish-shell
# Working directory is now /usr/src/fish-shell
prevd ::
# Working directory is now /usr/src
cd /usr/src
# Working directory is now /usr/src
cd /usr/src/fish-shell
# Working directory is now /usr/src/fish-shell
prevd
# Working directory is now /usr/src
nextd
# Working directory is now /usr/src/fish-shell
nextd
# Working directory is now /usr/src/fish-shell
\endfish

View file

@ -63,12 +63,18 @@ This file has been imported from the printf in GNU Coreutils version 6.9. If you
Example Example
------------ ------------
\fish
printf '%s\\t%s\\n' flounder fish
\endfish ::
printf '%s\\t%s\\n' flounder fish
Will print "flounder fish" (separated with a tab character), followed by a newline character. This is useful for writing completions, as fish expects completion scripts to output the option followed by the description, separated with a tab character. Will print "flounder fish" (separated with a tab character), followed by a newline character. This is useful for writing completions, as fish expects completion scripts to output the option followed by the description, separated with a tab character.
\fish
printf '%s:%d' "Number of bananas in my pocket" 42
\endfish ::
printf '%s:%d' "Number of bananas in my pocket" 42
Will print "Number of bananas in my pocket: 42", _without_ a newline. Will print "Number of bananas in my pocket: 42", _without_ a newline.

View file

@ -17,19 +17,22 @@ To change the number of characters per path component, set $fish_prompt_pwd_dir_
Examples Examples
------------ ------------
\fish{cli-dark}
>_ cd ~/
>_ echo $PWD
<outp>/home/alfa</outp>
>_ prompt_pwd
<outp>~</outp>
>_ cd /tmp/banana/sausage/with/mustard ::
>_ prompt_pwd
<outp>/t/b/s/w/mustard</outp> >_ cd ~/
>_ echo $PWD
<outp>/home/alfa</outp>
>_ prompt_pwd
<outp>~</outp>
>_ cd /tmp/banana/sausage/with/mustard
>_ prompt_pwd
<outp>/t/b/s/w/mustard</outp>
>_ set -g fish_prompt_pwd_dir_length 3
>_ prompt_pwd
<outp>/tmp/ban/sau/wit/mustard</outp>
>_ set -g fish_prompt_pwd_dir_length 3
>_ prompt_pwd
<outp>/tmp/ban/sau/wit/mustard</outp>
\endfish

View file

@ -23,10 +23,13 @@ The following options are available:
Example Example
------------ ------------
\fish
diff (sort a.txt | psub) (sort b.txt | psub)
# shows the difference between the sorted versions of files `a.txt` and `b.txt`.
source-highlight -f esc (cpp main.c | psub -f -s .c)
# highlights `main.c` after preprocessing as a C source. ::
\endfish
diff (sort a.txt | psub) (sort b.txt | psub)
# shows the difference between the sorted versions of files `a.txt` and `b.txt`.
source-highlight -f esc (cpp main.c | psub -f -s .c)
# highlights `main.c` after preprocessing as a C source.

View file

@ -25,24 +25,27 @@ You may be interested in the <a href="commands.html#cdh">`cdh`</a> command which
Example Example
------------ ------------
\fish
pushd /usr/src
# Working directory is now /usr/src
# Directory stack contains /usr/src
pushd /usr/src/fish-shell
# Working directory is now /usr/src/fish-shell
# Directory stack contains /usr/src /usr/src/fish-shell
pushd /tmp/ ::
# Working directory is now /tmp
# Directory stack contains /tmp /usr/src /usr/src/fish-shell
pushd +1 pushd /usr/src
# Working directory is now /usr/src # Working directory is now /usr/src
# Directory stack contains /usr/src /usr/src/fish-shell /tmp # Directory stack contains /usr/src
pushd /usr/src/fish-shell
# Working directory is now /usr/src/fish-shell
# Directory stack contains /usr/src /usr/src/fish-shell
pushd /tmp/
# Working directory is now /tmp
# Directory stack contains /tmp /usr/src /usr/src/fish-shell
pushd +1
# Working directory is now /usr/src
# Directory stack contains /usr/src /usr/src/fish-shell /tmp
popd
# Working directory is now /usr/src/fish-shell
# Directory stack contains /usr/src/fish-shell /tmp
popd
# Working directory is now /usr/src/fish-shell
# Directory stack contains /usr/src/fish-shell /tmp
\endfish

View file

@ -35,14 +35,20 @@ Example
The following code will count down from a random even number between 10 and 20 to 1: The following code will count down from a random even number between 10 and 20 to 1:
\fish
for i in (seq (random 10 2 20) -1 1)
echo $i ::
end
\endfish for i in (seq (random 10 2 20) -1 1)
echo $i
end
And this will open a random picture from any of the subdirectories: And this will open a random picture from any of the subdirectories:
\fish
open (random choice **jpg)
\endfish ::
open (random choice **jpg)

View file

@ -82,18 +82,21 @@ Example
The following code stores the value 'hello' in the shell variable `$foo`. The following code stores the value 'hello' in the shell variable `$foo`.
\fish
echo hello|read foo
# This is a neat way to handle command output by-line:
printf '%s\n' line1 line2 line3 line4 | while read -l foo
echo "This is another line: $foo"
end
# Delimiters given via "-d" are taken as one string ::
echo a==b==c | read -d == -l a b c
echo $a # a echo hello|read foo
echo $b # b
echo $c # c # This is a neat way to handle command output by-line:
printf '%s\n' line1 line2 line3 line4 | while read -l foo
echo "This is another line: $foo"
end
# Delimiters given via "-d" are taken as one string
echo a==b==c | read -d == -l a b c
echo $a # a
echo $b # b
echo $c # c
\endfish

View file

@ -20,10 +20,13 @@ Example
The following code is an implementation of the false command as a fish function The following code is an implementation of the false command as a fish function
\fish
function false
return 1 ::
end
\endfish function false
return 1
end

View file

@ -85,31 +85,34 @@ In assignment mode, `set` does not modify the exit status. This allows simultane
Examples Examples
------------ ------------
\fish
# Prints all global, exported variables.
set -xg
# Sets the value of the variable $foo to be 'hi'.
set foo hi
# Appends the value "there" to the variable $foo. ::
set -a foo there
# Does the same thing as the previous two commands the way it would be done pre-fish 3.0. # Prints all global, exported variables.
set foo hi set -xg
set foo $foo there
# Sets the value of the variable $foo to be 'hi'.
set foo hi
# Appends the value "there" to the variable $foo.
set -a foo there
# Does the same thing as the previous two commands the way it would be done pre-fish 3.0.
set foo hi
set foo $foo there
# Removes the variable $smurf
set -e smurf
# Changes the fourth element of the $PATH array to ~/bin
set PATH[4] ~/bin
# Outputs the path to Python if `type -p` returns true.
if set python_path (type -p python)
echo "Python is at $python_path"
end
# Removes the variable $smurf
set -e smurf
# Changes the fourth element of the $PATH array to ~/bin
set PATH[4] ~/bin
# Outputs the path to Python if `type -p` returns true.
if set python_path (type -p python)
echo "Python is at $python_path"
end
\endfish
Notes Notes
------------ ------------

View file

@ -42,12 +42,15 @@ Notes
Examples Examples
------------ ------------
\fish
set_color red; echo "Roses are red"
set_color blue; echo "Violets are blue" ::
set_color 62A; echo "Eggplants are dark purple"
set_color normal; echo "Normal is nice" # Resets the background too set_color red; echo "Roses are red"
\endfish set_color blue; echo "Violets are blue"
set_color 62A; echo "Eggplants are dark purple"
set_color normal; echo "Normal is nice" # Resets the background too
Terminal Capability Detection Terminal Capability Detection
------------ ------------

View file

@ -23,10 +23,13 @@ The return status of `source` is the return status of the last job to execute. I
Example Example
------------ ------------
\fish
source ~/.config/fish/config.fish
# Causes fish to re-read its initialization file. ::
\endfish
source ~/.config/fish/config.fish
# Causes fish to re-read its initialization file.
\subsection Caveats \subsection Caveats

View file

@ -188,193 +188,232 @@ And some other things:
Examples Examples
------------ ------------
\fish{cli-dark}
>_ string length 'hello, world'
<outp>12</outp>
>_ set str foo
>_ string length -q $str; echo $status
0
# Equivalent to test -n $str
\endfish
\fish{cli-dark} ::
>_ string sub --length 2 abcde
<outp>ab</outp>
>_ string sub -s 2 -l 2 abcde >_ string length 'hello, world'
<outp>bc</outp> <outp>12</outp>
>_ set str foo
>_ string length -q $str; echo $status
0
# Equivalent to test -n $str
>_ string sub --start=-2 abcde
<outp>de</outp>
\endfish
\fish{cli-dark}
>_ string split . example.com
<outp>example</outp>
<outp>com</outp>
>_ string split -r -m1 / /usr/local/bin/fish
<outp>/usr/local/bin</outp>
<outp>fish</outp>
>_ string split '' abc ::
<outp>a</outp>
<outp>b</outp>
<outp>c</outp>
\endfish
\fish{cli-dark} >_ string sub --length 2 abcde
>_ seq 3 | string join ... <outp>ab</outp>
<outp>1...2...3</outp>
\endfish >_ string sub -s 2 -l 2 abcde
<outp>bc</outp>
>_ string sub --start=-2 abcde
<outp>de</outp>
\fish{cli-dark}
>_ string trim ' abc '
<outp>abc</outp>
>_ string trim --right --chars=yz xyzzy zany
<outp>x</outp>
<outp>zan</outp>
\endfish
\fish{cli-dark}
>_ echo \\x07 | string escape
<bs>cg</bs>
\endfish
\fish{cli-dark} ::
>_ string escape --style=var 'a1 b2'\\u6161
<bs>a1_20b2__c_E6_85_A1</bs> >_ string split . example.com
\endfish <outp>example</outp>
<outp>com</outp>
>_ string split -r -m1 / /usr/local/bin/fish
<outp>/usr/local/bin</outp>
<outp>fish</outp>
>_ string split '' abc
<outp>a</outp>
<outp>b</outp>
<outp>c</outp>
::
>_ seq 3 | string join ...
<outp>1...2...3</outp>
::
>_ string trim ' abc '
<outp>abc</outp>
>_ string trim --right --chars=yz xyzzy zany
<outp>x</outp>
<outp>zan</outp>
::
>_ echo \\x07 | string escape
<bs>cg</bs>
::
>_ string escape --style=var 'a1 b2'\\u6161
<bs>a1_20b2__c_E6_85_A1</bs>
Match Glob Examples Match Glob Examples
------------ ------------
\fish{cli-dark}
>_ string match '?' a
<outp>a</outp>
>_ string match 'a*b' axxb
<outp>axxb</outp>
>_ string match -i 'a??B' Axxb ::
<outp>Axxb</outp>
>_ echo 'ok?' | string match '*\\?' >_ string match '?' a
<outp>ok?</outp> <outp>a</outp>
>_ string match 'a*b' axxb
<outp>axxb</outp>
>_ string match -i 'a??B' Axxb
<outp>Axxb</outp>
>_ echo 'ok?' | string match '*\\?'
<outp>ok?</outp>
# Note that only the second STRING will match here.
>_ string match 'foo' 'foo1' 'foo' 'foo2'
<outp>foo</outp>
>_ string match -e 'foo' 'foo1' 'foo' 'foo2'
<outp>foo1
foo
foo2
</outp>
>_ string match 'foo?' 'foo1' 'foo' 'foo2'
<outp>foo1
foo
foo2
</outp>
# Note that only the second STRING will match here.
>_ string match 'foo' 'foo1' 'foo' 'foo2'
<outp>foo</outp>
>_ string match -e 'foo' 'foo1' 'foo' 'foo2'
<outp>foo1
foo
foo2
</outp>
>_ string match 'foo?' 'foo1' 'foo' 'foo2'
<outp>foo1
foo
foo2
</outp>
\endfish
Match Regex Examples Match Regex Examples
------------ ------------
\fish{cli-dark}
>_ string match -r 'cat|dog|fish' 'nice dog'
<outp>dog</outp>
>_ string match -r -v "c.*[12]" {cat,dog}(seq 1 4)
<outp>dog1</outp>
<outp>dog2</outp>
<outp>cat3</outp>
<outp>dog3</outp>
<outp>cat4</outp>
<outp>dog4</outp>
>_ string match -r '(\\d\\d?):(\\d\\d):(\\d\\d)' <asis>2:34:56</asis> ::
<outp>2:34:56</outp>
<outp>2</outp>
<outp>34</outp>
<outp>56</outp>
>_ string match -r '^(\\w{{2,4}})\\g1$' papa mud murmur >_ string match -r 'cat|dog|fish' 'nice dog'
<outp>papa</outp> <outp>dog</outp>
<outp>pa</outp>
<outp>murmur</outp> >_ string match -r -v "c.*[12]" {cat,dog}(seq 1 4)
<outp>mur</outp> <outp>dog1</outp>
<outp>dog2</outp>
<outp>cat3</outp>
<outp>dog3</outp>
<outp>cat4</outp>
<outp>dog4</outp>
>_ string match -r '(\\d\\d?):(\\d\\d):(\\d\\d)' <asis>2:34:56</asis>
<outp>2:34:56</outp>
<outp>2</outp>
<outp>34</outp>
<outp>56</outp>
>_ string match -r '^(\\w{{2,4}})\\g1$' papa mud murmur
<outp>papa</outp>
<outp>pa</outp>
<outp>murmur</outp>
<outp>mur</outp>
>_ string match -r -a -n at ratatat
<outp>2 2</outp>
<outp>4 2</outp>
<outp>6 2</outp>
>_ string match -r -i '0x[0-9a-f]{{1,8}}' 'int magic = 0xBadC0de;'
<outp>0xBadC0de</outp>
>_ string match -r -a -n at ratatat
<outp>2 2</outp>
<outp>4 2</outp>
<outp>6 2</outp>
>_ string match -r -i '0x[0-9a-f]{{1,8}}' 'int magic = 0xBadC0de;'
<outp>0xBadC0de</outp>
\endfish
\subsection string-example-split0 NUL Delimited Examples \subsection string-example-split0 NUL Delimited Examples
\fish{cli-dark}
>_ # Count files in a directory, without being confused by newlines.
>_ count (find . -print0 | string split0)
<outp>42</outp>
>_ # Sort a list of elements which may contain newlines
>_ set foo beta alpha\\ngamma ::
>_ set foo (string join0 $foo | sort -z | string split0)
>_ string escape $foo[1] >_ # Count files in a directory, without being confused by newlines.
<outp>alpha\\ngamma</outp> >_ count (find . -print0 | string split0)
\endfish <outp>42</outp>
>_ # Sort a list of elements which may contain newlines
>_ set foo beta alpha\\ngamma
>_ set foo (string join0 $foo | sort -z | string split0)
>_ string escape $foo[1]
<outp>alpha\\ngamma</outp>
Replace Literal Examples Replace Literal Examples
------------ ------------
\fish{cli-dark}
>_ string replace is was 'blue is my favorite'
<outp>blue was my favorite</outp>
>_ string replace 3rd last 1st 2nd 3rd
<outp>1st</outp>
<outp>2nd</outp>
<outp>last</outp>
>_ string replace -a ' ' _ 'spaces to underscores' ::
<outp>spaces_to_underscores</outp>
\endfish >_ string replace is was 'blue is my favorite'
<outp>blue was my favorite</outp>
>_ string replace 3rd last 1st 2nd 3rd
<outp>1st</outp>
<outp>2nd</outp>
<outp>last</outp>
>_ string replace -a ' ' _ 'spaces to underscores'
<outp>spaces_to_underscores</outp>
Replace Regex Examples Replace Regex Examples
------------ ------------
\fish{cli-dark}
>_ string replace -r -a '[^\\d.]+' ' ' '0 one two 3.14 four 5x'
<outp>0 3.14 5</outp>
>_ string replace -r '(\\w+)\\s+(\\w+)' '$2 $1 $$' 'left right'
<outp>right left $</outp>
>_ string replace -r '\\s*newline\\s*' '\\n' 'put a newline here' ::
<outp>put a</outp>
<outp>here</outp> >_ string replace -r -a '[^\\d.]+' ' ' '0 one two 3.14 four 5x'
\endfish <outp>0 3.14 5</outp>
>_ string replace -r '(\\w+)\\s+(\\w+)' '$2 $1 $$' 'left right'
<outp>right left $</outp>
>_ string replace -r '\\s*newline\\s*' '\\n' 'put a newline here'
<outp>put a</outp>
<outp>here</outp>
Repeat Examples Repeat Examples
------------ ------------
\fish{cli-dark}
>_ string repeat -n 2 'foo '
<outp>foo foo</outp>
>_ echo foo | string repeat -n 2
<outp>foofoo</outp>
>_ string repeat -n 2 -m 5 'foo' ::
<outp>foofo</outp>
>_ string repeat -n 2 'foo '
<outp>foo foo</outp>
>_ echo foo | string repeat -n 2
<outp>foofoo</outp>
>_ string repeat -n 2 -m 5 'foo'
<outp>foofo</outp>
>_ string repeat -m 5 'foo'
<outp>foofo</outp>
>_ string repeat -m 5 'foo'
<outp>foofo</outp>
\endfish

View file

@ -24,20 +24,23 @@ Example
If the variable \$animal contains the name of an animal, the following code would attempt to classify it: If the variable \$animal contains the name of an animal, the following code would attempt to classify it:
\fish
switch $animal
case cat ::
echo evil
case wolf dog human moose dolphin whale switch $animal
echo mammal case cat
case duck goose albatross echo evil
echo bird case wolf dog human moose dolphin whale
case shark trout stingray echo mammal
echo fish case duck goose albatross
case '*' echo bird
echo I have no idea what a $animal is case shark trout stingray
end echo fish
\endfish case '*'
echo I have no idea what a $animal is
end
If the above code was run with `$animal` set to `whale`, the output If the above code was run with `$animal` set to `whale`, the output
would be `mammal`. would be `mammal`.

View file

@ -109,59 +109,80 @@ Examples
If the `/tmp` directory exists, copy the `/etc/motd` file to it: If the `/tmp` directory exists, copy the `/etc/motd` file to it:
\fish
if test -d /tmp
cp /etc/motd /tmp/motd ::
end
\endfish if test -d /tmp
cp /etc/motd /tmp/motd
end
If the variable `MANPATH` is defined and not empty, print the contents. (If `MANPATH` is not defined, then it will expand to zero arguments, unless quoted.) If the variable `MANPATH` is defined and not empty, print the contents. (If `MANPATH` is not defined, then it will expand to zero arguments, unless quoted.)
\fish
if test -n "$MANPATH"
echo $MANPATH ::
end
\endfish if test -n "$MANPATH"
echo $MANPATH
end
Parentheses and the `-o` and `-a` operators can be combined to produce more complicated expressions. In this example, success is printed if there is a `/foo` or `/bar` file as well as a `/baz` or `/bat` file. Parentheses and the `-o` and `-a` operators can be combined to produce more complicated expressions. In this example, success is printed if there is a `/foo` or `/bar` file as well as a `/baz` or `/bat` file.
\fish
if test \( -f /foo -o -f /bar \) -a \( -f /baz -o -f /bat \)
echo Success. ::
end.
\endfish if test \( -f /foo -o -f /bar \) -a \( -f /baz -o -f /bat \)
echo Success.
end.
Numerical comparisons will simply fail if one of the operands is not a number: Numerical comparisons will simply fail if one of the operands is not a number:
\fish
if test 42 -eq "The answer to life, the universe and everything"
echo So long and thanks for all the fish # will not be executed ::
end
\endfish if test 42 -eq "The answer to life, the universe and everything"
echo So long and thanks for all the fish # will not be executed
end
A common comparison is with $status: A common comparison is with $status:
\fish
if test $status -eq 0
echo "Previous command succeeded" ::
end
\endfish if test $status -eq 0
echo "Previous command succeeded"
end
The previous test can likewise be inverted: The previous test can likewise be inverted:
\fish
if test ! $status -eq 0
echo "Previous command failed" ::
end
\endfish if test ! $status -eq 0
echo "Previous command failed"
end
which is logically equivalent to the following: which is logically equivalent to the following:
\fish
if test $status -ne 0
echo "Previous command failed" ::
end
\endfish if test $status -ne 0
echo "Previous command failed"
end
Standards Standards
------------ ------------

View file

@ -35,7 +35,10 @@ The return status is 1 if any `REASON` is invalid; otherwise trap returns 0.
Example Example
------------ ------------
\fish
trap "status --print-stack-trace" SIGUSR1
# Prints a stack trace each time the SIGUSR1 signal is sent to the shell. ::
\endfish
trap "status --print-stack-trace" SIGUSR1
# Prints a stack trace each time the SIGUSR1 signal is sent to the shell.

View file

@ -32,7 +32,10 @@ The `-q`, `-p`, `-t` and `-P` flags (and their long flag aliases) are mutually e
Example Example
------------ ------------
\fish{cli-dark}
>_ type fg
<outp>fg is a builtin</outp> ::
\endfish
>_ type fg
<outp>fg is a builtin</outp>

View file

@ -20,19 +20,28 @@ Description
Example Example
------------ ------------
\fish
sleep 10 &
wait $last_pid ::
\endfish
sleep 10 &
wait $last_pid
spawns `sleep` in the background, and then waits until it finishes. spawns `sleep` in the background, and then waits until it finishes.
\fish
for i in (seq 1 5); sleep 10 &; end
wait ::
\endfish
for i in (seq 1 5); sleep 10 &; end
wait
spawns five jobs in the background, and then waits until all of them finishes. spawns five jobs in the background, and then waits until all of them finishes.
\fish
for i in (seq 1 5); sleep 10 &; end
hoge & ::
wait sleep
\endfish for i in (seq 1 5); sleep 10 &; end
hoge &
wait sleep
spawns five jobs and `hoge` in the background, and then waits until all `sleep`s finishes, and doesn't wait for `hoge` finishing. spawns five jobs and `hoge` in the background, and then waits until all `sleep`s finishes, and doesn't wait for `hoge` finishing.

View file

@ -22,7 +22,10 @@ You can use <a href="#and">`and`</a> or <a href="#or">`or`</a> for complex condi
Example Example
------------ ------------
\fish
while test -f foo.txt; or test -f bar.txt ; echo file exists; sleep 10; end
# outputs 'file exists' at 10 second intervals as long as the file foo.txt or bar.txt exists. ::
\endfish
while test -f foo.txt; or test -f bar.txt ; echo file exists; sleep 10; end
# outputs 'file exists' at 10 second intervals as long as the file foo.txt or bar.txt exists.