These are all described below.
COMMAND1; and COMMAND2and builtin is used to execute a command if the current exit status (as set by the last previous command) is 0.The and command does not change the current exit status.
The exit status of the last foreground command to exit can always be accessed using the $status variable.
make command to build a program, if the build succceds, the program is installed. If either step fails, make clean is run, which removes the files created by the build process
make; and make install; or make clean
Back to index.
begin; [COMMANDS...;] endbegin builtin is used to create a new block of code. The block is unconditionally executed. begin; ...; end is equivalent to if true; ...; end. The begin command is used to group any number of commands into a block. The reason for doing so is usually either to introduce a new variable scope, to redirect the input or output of a set of commands as a group, or to specify precedence when using the conditional commands like and.
The begin command does not change the current exit status.
begin set -x PIRATE Yarrr ... end # This will not output anything, since PIRATE went out of scope at the end of # the block and was killed echo $PIRATE
In the following code, all output is redirected to the file out.html.
begin echo $xml_header echo $html_header if test -e $file ... end ...
end > out.html
Back to index.
bg [PID...]The PID of the desired process is usually found by using process globbing.
bg %0 will put the job with job id 0 in the background.Back to index.
bind [OPTIONS] [BINDINGS...]
The bind builtin causes fish to add the readline style bindings specified by BINDINGS to the list of key bindings, as if they appeared in your ~/.fish_inputrc file.
For more information on the syntax keyboard bindings, use man readline to access the readline documentation. The availiable commands are listed in the Command Line Editor section of the fish manual - but you may also use any fish command! To write such commands, see the commandline builtin. It's good practice to put the code into a function -b and bind to the function name.
-M MODE or --set-mode=MODE sets the current input mode to MODE.bind -M vi changes to the vi input mode
bind '"\M-j": jobs' Binds the jobs command to the Alt-j keyboard shortcut
Back to index.
block [OPTIONS...]-l or --local Release the block at the end of the currently innermost block scope-g or --global Never automatically release the lock-e or --erase Release global blockblock -g #Do something that should not be interrupted block -e
Back to index.
LOOP_CONSTRUCT; [COMMANDS...] break; [COMMANDS...] endbreak builtin is used to halt a currently running loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement.
for i in *.c
if grep smurf $i
echo Smurfs are present in $i
break
end
end
Back to index.
builtin BUILTINNAME [OPTIONS...]-n or --names List the names of all defined builtinsPrefixing a command with the word 'builtin' forces fish to ignore any aliases with the same name.
builtin jobscauses fish to execute the jobs builtin, even if a function named jobs exists.
Back to index.
switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] endswitch statement is used to perform one of several blocks of commands depending on whether a specified value equals one of several wildcarded values. The case statement is used together with the switch statement in order to determine which block should be performed.
Each case command is given one or more parameter. The first case command with a parameter that matches the string specified in the switch command will be evaluated. case parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames.
Note that fish does not fall through on case statements. Though the syntax may look a bit like C switch statements, it behaves more like the case stamantes of traditional shells.
Also note that command substitutions in a case statement will be evaluated even if it's body is not taken. This may seem counterintuitive at first, but it is unavoidable, since it would be impossible to know if a case command will evaluate to true before all forms of parameter expansion have been performed for the case command.
switch $animal
case cat
echo evil
case wolf dog human moose dolphin whale
echo mammal
case duck goose albatross
echo bird
case shark trout stingray
echo fish
case '*'
echo I have no idea what a $animal is
end
If the above code was run with $animal set to whale, the output would be mammal.
Back to index.
cd [DIRECTORY]DIRECTORY is supplied it will become the new directory. If DIRECTORY is a relative path, the paths found in the CDPATH environment variable array will be tried as prefixes for the specified path. If CDPATH is not set, it is assumed to be '.'. If DIRECTORY is not specified, $HOME will be the new directory.Back to index.
commandline [OPTIONS] [CMD]CMD is the new value of the commandline. If unspecified, the current value of the commandline is written to standard output.The following switches change what the commandline builtin does
-C or --cursor set or get the current cursor position, not the contents of the buffer. If no argument is given, the current cursor position is printed, otherwise the argument is interpreted as the new cursor position.-f or --function inject readline functions into the reader. This option can not be combined with any other option. It will cause any additional arguments to be interpreted as readline functions, and these functions will be injected into the reader, so that they will be returned to the reader before any additional actual keypresses are read.
The following switches change the way commandline updates the commandline buffer
-a or --append do not remove the current commandline, append the specified string at the end of it-i or --insert do not remove the current commandline, insert the specified string at the current cursor position-r or --replace remove the current commandline and replace it with the specified string (default)The following switches change what part of the commandline is printed or updated
-b or --current-buffer select the entire buffer (default)-j or --current-job select the current job-p or --current-process select the current process-t or --current-token select the current token.
The following switch changes the way commandline prints the current commandline buffer
-c or --cut-at-cursor only print selection up until the current cursor position-o or --tokenize tokenize the selection and print one string-type token per line
If commandline is called during a call to complete a given string using complete -C STRING, commandline will consider the specified string to be the current contents of the commandline.
commandline -j $history[3]replaces the job under the cursor with the third item from the commandline history.
Back to index.
command COMMANDNAME [OPTIONS...]command lscauses fish to execute the ls program, even if there exists a 'ls' alias.
Back to index.
complete (-c|--command|-p|--path) COMMAND [(-s|--short-option) SHORT_OPTION] [(-l|--long-option|-o|--old-option) LONG_OPTION [(-a||--arguments) OPTION_ARGUMENTS] [(-d|--description) DESCRIPTION]
COMMAND is the name of the command for which to add a completionSHORT_OPTION is a one character option for the commandLONG_OPTION is a multi character option for the commandOPTION_ARGUMENTS is parameter containing a space-separated list of possible option-arguments, which may contain subshellsDESCRIPTION is a description of what the option and/or option arguments do-C STRING or --do-complete=STRING makes complete try to find all possible completions for the specified string-e or --erase implies that the specified completion should be deleted-f or --no-files specifies that the option specified by this completion may not be followed by a filename-n or --condition specifies a shell command that must return 0 if the completion is to be used. This makes it possible to specify completions that should only be used in some cases.-o or --old-option implies that the command uses old long style options with only one dash-p or --path implies that the string COMMAND is the full path of the command-r or --require-parameter specifies that the option specified by this completion always must have an option argument, i.e. may not be followed by another option-u or --unauthorative implies that there may be more options than the ones specified, and that fish should not assume that options not listed are spelling errors-x or --exclusive implies both -r and -f
Command specific tab-completions in fish are based on the notion of options and arguments. An option is a parameter which begins with a hyphen, such as '-h', '-help' or '--help'. Arguments are parameters that do not begin with a hyphen. Fish recognizes three styles of options, the same styles as the GNU version of the getopt library. These styles are:
The options for specifying command name, command path, or command switches may all be used multiple times to specify multiple commands which have the same completion or multiple switches accepted by a command.
When erasing completions, it is possible to either erase all completions for a specific command by specifying complete -e -c COMMAND, or by specifying a specific completion option to delete by specifying either a long, short or old style option.
-o for the gcc command requires that a file follows it. This can be done using writing 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 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: 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.
This can be written as:
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 commandline buffer for the presence of a specified set of options.
Back to index.
contains [OPTIONS] KEY [VALUES...]-h or --help display this messageTest if the set VALUES contains the string KEY. Return status is 0 if yes, 1 otherwise
for i in ~/bin /usr/local/bin if not contains $i $PATH set PATH $PATH i end end
The above code tests if ~/bin and /usr/local/bin are in the path and if they are not, they are added.
Back to index.
LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] endcontinue builtin is used to skip the current lap of the innermost currently running loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement.
for i in *.tmp
if grep smurf $i
continue
end
rm $i
end
Back to index.
count $VARIABLEcount prints the number of arguments that were passed to it. This is usually used to find out how many elements an environment variable array contains, but this is not the only potential usage for the count command.
The count command does not accept any options, not even '-h'. This way the user does not have to worry about an array containing elements such as dashes. fish performs a special check when invoking the count program, and if the user uses a help option, this help page is displayed, but if a help option is contained inside of a variable or is the result of expansion, it will be passed on to the count program.
Count exits with a non-zero exit status if no arguments where passed to it, with zero otherwise.
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'.
Back to index.
dirhdirh prints the current directory history. The current position in the history is highlighted using $fish_color_history_current.Back to index.
dirsdirs prints the current directory stack.Back to index.
if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] endif will execute the command CONDITION. If the condition's exit status is 0, the commands COMMANDS_TRUE will execute. If it is not 0 and else is given, COMMANDS_FALSE will be executed. HintAs builtin, even if a function named jobs exists.Back to index.
switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] endswitch statement is used to perform one of several blocks of commands depending on whether a specified value equals one of several wildcarded values. The case statement is used together with the switch statement in order to determine which block should be performed.
Each case command is given one or more parameter. The first case command with a parameter that matches the string specified in the switch command will be evaluated. case parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames.
Note that fish does not fall through on case statements. Though the syntax may look a bit like C switch statements, it behaves more like the case stamantes of traditional shells.
Also note that command substitutions in a case statement will be evaluated even if it's body is not taken. This may seem counterintuitive at first, but it is unavoidable, since it would be impossible to know if a case command will evaluate to true before all forms of parameter expansion have been performed for the case command.
switch $animal
case cat
echo evil
case wolf dog human moose dolphin whale
echo mammal
case duck goose albatross
echo bird
case shark trout stingray
echo fish
case '*'
echo I have no idea what a $animal is
end
If the above code was run with $animal set to whale, the output would be mammal.
Back to index.
cd [DIRECTORY]DIRECTORY is supplied it will become the new directory. If DIRECTORY is a relative path, the paths found in the CDPATH environment variable array will be tried as prefixes for the specified path. If CDPATH is not set, it is assumed to be '.'. If DIRECTORY is not specified, $HOME will be the new directory.Back to index.
commandline [OPTIONS] [CMD]CMD is the new value of the commandline. If unspecified, the current value of the commandline is written to standard output.The following switches change what the commandline builtin does
-C or --cursor set or get the current cursor position, not the contents of the buffer. If no argument is given, the current cursor position is printed, otherwise the argument is interpreted as the new cursor position.-f or --function inject readline functions into the reader. This option can not be combined with any other option. It will cause any additional arguments to be interpreted as readline functions, and these functions will be injected into the reader, so that they will be returned to the reader before any additional actual keypresses are read.
The following switches change the way commandline updates the commandline buffer
-a or --append do not remove the current commandline, append the specified string at the end of it-i or --insert do not remove the current commandline, insert the specified string at the current cursor position-r or --replace remove the current commandline and replace it with the specified string (default)The following switches change what part of the commandline is printed or updated
-b or --current-buffer select the entire buffer (default)-j or --current-job select the current job-p or --current-process select the current process-t or --current-token select the current token.
The following switch changes the way commandline prints the current commandline buffer
-c or --cut-at-cursor only print selection up until the current cursor position-o or --tokenize tokenize the selection and print one string-type token per line
If commandline is called during a call to complete a given string using complete -C STRING, commandline will consider the specified string to be the current contents of the commandline.
commandline -j $history[3]replaces the job under the cursor with the third item from the commandline history.
Back to index.
command COMMANDNAME [OPTIONS...]command lscauses fish to execute the ls program, even if there exists a 'ls' alias.
Back to index.
complete (-c|--command|-p|--path) COMMAND [(-s|--short-option) SHORT_OPTION] [(-l|--long-option|-o|--old-option) LONG_OPTION [(-a||--arguments) OPTION_ARGUMENTS] [(-d|--description) DESCRIPTION]
COMMAND is the name of the command for which to add a completionSHORT_OPTION is a one character option for the commandLONG_OPTION is a multi character option for the commandOPTION_ARGUMENTS is parameter containing a space-separated list of possible option-arguments, which may contain subshellsDESCRIPTION is a description of what the option and/or option arguments do-C STRING or --do-complete=STRING makes complete try to find all possible completions for the specified string-e or --erase implies that the specified completion should be deleted-f or --no-files specifies that the option specified by this completion may not be followed by a filename-n or --condition specifies a shell command that must return 0 if the completion is to be used. This makes it possible to specify completions that should only be used in some cases.-o or --old-option implies that the command uses old long style options with only one dash-p or --path implies that the string COMMAND is the full path of the command-r or --require-parameter specifies that the option specified by this completion always must have an option argument, i.e. may not be followed by another option-u or --unauthorative implies that there may be more options than the ones specified, and that fish should not assume that options not listed are spelling errors-x or --exclusive implies both -r and -f
Command specific tab-completions in fish are based on the notion of options and arguments. An option is a parameter which begins with a hyphen, such as '-h', '-help' or '--help'. Arguments are parameters that do not begin with a hyphen. Fish recognizes three styles of options, the same styles as the GNU version of the getopt library. These styles are:
The options for specifying command name, command path, or command switches may all be used multiple times to specify multiple commands which have the same completion or multiple switches accepted by a command.
When erasing completions, it is possible to either erase all completions for a specific command by specifying complete -e -c COMMAND, or by specifying a specific completion option to delete by specifying either a long, short or old style option.
-o for the gcc command requires that a file follows it. This can be done using writing 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 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: 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.
This can be written as:
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 commandline buffer for the presence of a specified set of options.
Back to index.
contains [OPTIONS] KEY [VALUES...]-h or --help display this messageTest if the set VALUES contains the string KEY. Return status is 0 if yes, 1 otherwise
for i in ~/bin /usr/local/bin if not contains $i $PATH set PATH $PATH i end end
The above code tests if ~/bin and /usr/local/bin are in the path and if they are not, they are added.
Back to index.
LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] endcontinue builtin is used to skip the current lap of the innermost currently running loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement.
for i in *.tmp
if grep smurf $i
continue
end
rm $i
end
Back to index.
count $VARIABLEcount prints the number of arguments that were passed to it. This is usually used to find out how many elements an environment variable array contains, but this is not the only potential usage for the count command.
The count command does not accept any options, not even '-h'. This way the user does not have to worry about an array containing elements such as dashes. fish performs a special check when invoking the count program, and if the user uses a help option, this help page is displayed, but if a help option is contained inside of a variable or is the result of expansion, it will be passed on to the count program.
Count exits with a non-zero exit status if no arguments where passed to it, with zero otherwise.
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'.
Back to index.
dirhdirh prints the current directory history. The current position in the history is highlighted using $fish_color_history_current.Back to index.
dirsdirs prints the current directory stack.Back to index.
if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] endif will execute the command CONDITION. If the condition's exit status is 0, the commands COMMANDS_TRUE will execute. If it is not 0 and else is given, COMMANDS_FALSE will be executed. HintAs builtin, even if a function named jobs exists.Back to index.
switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] endswitch statement is used to perform one of several blocks of commands depending on whether a specified value equals one of several wildcarded values. The case statement is used together with the switch statement in order to determine which block should be performed.
Each case command is given one or more parameter. The first case command with a parameter that matches the string specified in the switch command will be evaluated. case parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames.
Note that fish does not fall through on case statements. Though the syntax may look a bit like C switch statements, it behaves more like the case stamantes of traditional shells.
Also note that command substitutions in a case statement will be evaluated even if it's body is not taken. This may seem counterintuitive at first, but it is unavoidable, since it would be impossible to know if a case command will evaluate to true before all forms of parameter expansion have been performed for the case command.
switch $animal
case cat
echo evil
case wolf dog human moose dolphin whale
echo mammal
case duck goose albatross
echo bird
case shark trout stingray
echo fish
case '*'
echo I have no idea what a $animal is
end
If the above code was run with $animal set to whale, the output would be mammal.
Back to index.
cd [DIRECTORY]DIRECTORY is supplied it will become the new directory. If DIRECTORY is a relative path, the paths found in the CDPATH environment variable array will be tried as prefixes for the specified path. If CDPATH is not set, it is assumed to be '.'. If DIRECTORY is not specified, $HOME will be the new directory.Back to index.
commandline [OPTIONS] [CMD]CMD is the new value of the commandline. If unspecified, the current value of the commandline is written to standard output.The following switches change what the commandline builtin does
-C or --cursor set or get the current cursor position, not the contents of the buffer. If no argument is given, the current cursor position is printed, otherwise the argument is interpreted as the new cursor position.-f or --function inject readline functions into the reader. This option can not be combined with any other option. It will cause any additional arguments to be interpreted as readline functions, and these functions will be injected into the reader, so that they will be returned to the reader before any additional actual keypresses are read.
The following switches change the way commandline updates the commandline buffer
-a or --append do not remove the current commandline, append the specified string at the end of it-i or --insert do not remove the current commandline, insert the specified string at the current cursor position-r or --replace remove the current commandline and replace it with the specified string (default)The following switches change what part of the commandline is printed or updated
-b or --current-buffer select the entire buffer (default)-j or --current-job select the current job-p or --current-process select the current process-t or --current-token select the current token.
The following switch changes the way commandline prints the current commandline buffer
-c or --cut-at-cursor only print selection up until the current cursor position-o or --tokenize tokenize the selection and print one string-type token per line
If commandline is called during a call to complete a given string using complete -C STRING, commandline will consider the specified string to be the current contents of the commandline.
commandline -j $history[3]replaces the job under the cursor with the third item from the commandline history.
Back to index.
command COMMANDNAME [OPTIONS...]command lscauses fish to execute the ls program, even if there exists a 'ls' alias.
Back to index.
complete (-c|--command|-p|--path) COMMAND [(-s|--short-option) SHORT_OPTION] [(-l|--long-option|-o|--old-option) LONG_OPTION [(-a||--arguments) OPTION_ARGUMENTS] [(-d|--description) DESCRIPTION]
COMMAND is the name of the command for which to add a completionSHORT_OPTION is a one character option for the commandLONG_OPTION is a multi character option for the commandOPTION_ARGUMENTS is parameter containing a space-separated list of possible option-arguments, which may contain subshellsDESCRIPTION is a description of what the option and/or option arguments do-C STRING or --do-complete=STRING makes complete try to find all possible completions for the specified string-e or --erase implies that the specified completion should be deleted-f or --no-files specifies that the option specified by this completion may not be followed by a filename-n or --condition specifies a shell command that must return 0 if the completion is to be used. This makes it possible to specify completions that should only be used in some cases.-o or --old-option implies that the command uses old long style options with only one dash-p or --path implies that the string COMMAND is the full path of the command-r or --require-parameter specifies that the option specified by this completion always must have an option argument, i.e. may not be followed by another option-u or --unauthorative implies that there may be more options than the ones specified, and that fish should not assume that options not listed are spelling errors-x or --exclusive implies both -r and -f
Command specific tab-completions in fish are based on the notion of options and arguments. An option is a parameter which begins with a hyphen, such as '-h', '-help' or '--help'. Arguments are parameters that do not begin with a hyphen. Fish recognizes three styles of options, the same styles as the GNU version of the getopt library. These styles are:
The options for specifying command name, command path, or command switches may all be used multiple times to specify multiple commands which have the same completion or multiple switches accepted by a command.
When erasing completions, it is possible to either erase all completions for a specific command by specifying complete -e -c COMMAND, or by specifying a specific completion option to delete by specifying either a long, short or old style option.
-o for the gcc command requires that a file follows it. This can be done using writing 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 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: 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.
This can be written as:
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 commandline buffer for the presence of a specified set of options.
Back to index.
contains [OPTIONS] KEY [VALUES...]-h or --help display this messageTest if the set VALUES contains the string KEY. Return status is 0 if yes, 1 otherwise
for i in ~/bin /usr/local/bin if not contains $i $PATH set PATH $PATH i end end
The above code tests if ~/bin and /usr/local/bin are in the path and if they are not, they are added.
Back to index.
LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] endcontinue builtin is used to skip the current lap of the innermost currently running loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement.
for i in *.tmp
if grep smurf $i
continue
end
rm $i
end
Back to index.
count $VARIABLEcount prints the number of arguments that were passed to it. This is usually used to find out how many elements an environment variable array contains, but this is not the only potential usage for the count command.
The count command does not accept any options, not even '-h'. This way the user does not have to worry about an array containing elements such as dashes. fish performs a special check when invoking the count program, and if the user uses a help option, this help page is displayed, but if a help option is contained inside of a variable or is the result of expansion, it will be passed on to the count program.
Count exits with a non-zero exit status if no arguments where passed to it, with zero otherwise.
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'.
Back to index.
dirhdirh prints the current directory history. The current position in the history is highlighted using $fish_color_history_current.Back to index.
dirsdirs prints the current directory stack.Back to index.
if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] endif will execute the command CONDITION. If the condition's exit status is 0, the commands COMMANDS_TRUE will execute. If it is not 0 and else is given, COMMANDS_FALSE will be executed. HintAs builtin, even if a function named jobs exists.Back to index.
switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] endswitch statement is used to perform one of several blocks of commands depending on whether a specified value equals one of several wildcarded values. The case statement is used together with the switch statement in order to determine which block should be performed.
Each case command is given one or more parameter. The first case command with a parameter that matches the string specified in the switch command will be evaluated. case parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames.
Note that fish does not fall through on case statements. Though the syntax may look a bit like C switch statements, it behaves more like the case stamantes of traditional shells.
Also note that command substitutions in a case statement will be evaluated even if it's body is not taken. This may seem counterintuitive at first, but it is unavoidable, since it would be impossible to know if a case command will evaluate to true before all forms of parameter expansion have been performed for the case command.
switch $animal
case cat
echo evil
case wolf dog human moose dolphin whale
echo mammal
case duck goose albatross
echo bird
case shark trout stingray
echo fish
case '*'
echo I have no idea what a $animal is
end
If the above code was run with $animal set to whale, the output would be mammal.
Back to index.
cd [DIRECTORY]DIRECTORY is supplied it will become the new directory. If DIRECTORY is a relative path, the paths found in the CDPATH environment variable array will be tried as prefixes for the specified path. If CDPATH is not set, it is assumed to be '.'. If DIRECTORY is not specified, $HOME will be the new directory.Back to index.
commandline [OPTIONS] [CMD]CMD is the new value of the commandline. If unspecified, the current value of the commandline is written to standard output.The following switches change what the commandline builtin does
-C or --cursor set or get the current cursor position, not the contents of the buffer. If no argument is given, the current cursor position is printed, otherwise the argument is interpreted as the new cursor position.-f or --function inject readline functions into the reader. This option can not be combined with any other option. It will cause any additional arguments to be interpreted as readline functions, and these functions will be injected into the reader, so that they will be returned to the reader before any additional actual keypresses are read.
The following switches change the way commandline updates the commandline buffer
-a or --append do not remove the current commandline, append the specified string at the end of it-i or --insert do not remove the current commandline, insert the specified string at the current cursor position-r or --replace remove the current commandline and replace it with the specified string (default)The following switches change what part of the commandline is printed or updated
-b or --current-buffer select the entire buffer (default)-j or --current-job select the current job-p or --current-process select the current process-t or --current-token select the current token.
The following switch changes the way commandline prints the current commandline buffer
-c or --cut-at-cursor only print selection up until the current cursor position-o or --tokenize tokenize the selection and print one string-type token per line
If commandline is called during a call to complete a given string using complete -C STRING, commandline will consider the specified string to be the current contents of the commandline.
commandline -j $history[3]replaces the job under the cursor with the third item from the commandline history.
Back to index.
command COMMANDNAME [OPTIONS...]command lscauses fish to execute the ls program, even if there exists a 'ls' alias.
Back to index.
complete (-c|--command|-p|--path) COMMAND [(-s|--short-option) SHORT_OPTION] [(-l|--long-option|-o|--old-option) LONG_OPTION [(-a||--arguments) OPTION_ARGUMENTS] [(-d|--description) DESCRIPTION]
COMMAND is the name of the command for which to add a completionSHORT_OPTION is a one character option for the commandLONG_OPTION is a multi character option for the commandOPTION_ARGUMENTS is parameter containing a space-separated list of possible option-arguments, which may contain subshellsDESCRIPTION is a description of what the option and/or option arguments do-C STRING or --do-complete=STRING makes complete try to find all possible completions for the specified string-e or --erase implies that the specified completion should be deleted-f or --no-files specifies that the option specified by this completion may not be followed by a filename-n or --condition specifies a shell command that must return 0 if the completion is to be used. This makes it possible to specify completions that should only be used in some cases.-o or --old-option implies that the command uses old long style options with only one dash-p or --path implies that the string COMMAND is the full path of the command-r or --require-parameter specifies that the option specified by this completion always must have an option argument, i.e. may not be followed by another option-u or --unauthorative implies that there may be more options than the ones specified, and that fish should not assume that options not listed are spelling errors-x or --exclusive implies both -r and -f
Command specific tab-completions in fish are based on the notion of options and arguments. An option is a parameter which begins with a hyphen, such as '-h', '-help' or '--help'. Arguments are parameters that do not begin with a hyphen. Fish recognizes three styles of options, the same styles as the GNU version of the getopt library. These styles are:
The options for specifying command name, command path, or command switches may all be used multiple times to specify multiple commands which have the same completion or multiple switches accepted by a command.
When erasing completions, it is possible to either erase all completions for a specific command by specifying complete -e -c COMMAND, or by specifying a specific completion option to delete by specifying either a long, short or old style option.
-o for the gcc command requires that a file follows it. This can be done using writing 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 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: 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.
This can be written as:
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 commandline buffer for the presence of a specified set of options.
Back to index.
contains [OPTIONS] KEY [VALUES...]-h or --help display this messageTest if the set VALUES contains the string KEY. Return status is 0 if yes, 1 otherwise
for i in ~/bin /usr/local/bin if not contains $i $PATH set PATH $PATH i end end
The above code tests if ~/bin and /usr/local/bin are in the path and if they are not, they are added.
Back to index.
LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] endcontinue builtin is used to skip the current lap of the innermost currently running loop, such as a for loop or a while loop. It is usually added inside of a conditional block such as an if statement or a switch statement.
for i in *.tmp
if grep smurf $i
continue
end
rm $i
end
Back to index.
count $VARIABLEcount prints the number of arguments that were passed to it. This is usually used to find out how many elements an environment variable array contains, but this is not the only potential usage for the count command.
The count command does not accept any options, not even '-h'. This way the user does not have to worry about an array containing elements such as dashes. fish performs a special check when invoking the count program, and if the user uses a help option, this help page is displayed, but if a help option is contained inside of a variable or is the result of expansion, it will be passed on to the count program.
Count exits with a non-zero exit status if no arguments where passed to it, with zero otherwise.
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'.
Back to index.
dirhdirh prints the current directory history. The current position in the history is highlighted using $fish_color_history_current.Back to index.
dirsdirs prints the current directory stack.Back to index.
if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] endif will execute the command CONDITION. If the condition's exit status is 0, the commands COMMANDS_TRUE will execute. If it is not 0 and else is given, COMMANDS_FALSE will be executed. HintAs builtin, even if a function named jobs exists.