fish home | Main documentation page | Design document | Commands | FAQ | License

Commands, functions and builtins bundled with fish

Fish ships with a large number of builtin commands, shellscript functions and external commands.

These are all described below.


and - conditionally execute a command

Synopsis

COMMAND1; and COMMAND2

Description

The and 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.

Example

The following code runs the 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 - start a new block of code

Synopsis

begin; [COMMANDS...;] end

Description

The begin 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.

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.

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 - send to background

Synopsis

bg [PID...]

Description

Sends the specified jobs to the background. A background job is executed simultaneously with fish, and does not have access to the keyboard. If no job is specified, the last job to be used is put in the background. If PID is specified, the jobs with the specified group ids are put in the background.

The PID of the desired process is usually found by using process globbing.

Example

bg %0 will put the job with job id 0 in the background.

Back to index.


bind - handle key bindings

Synopsis

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.

Description

Example

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 - temporarily block delivery of events

Synopsis

block [OPTIONS...]

Description

Example

block -g
#Do something that should not be interrupted
block -e

Back to index.


break - stop the innermost currently evaluated loop

Synopsis

LOOP_CONSTRUCT; [COMMANDS...] break; [COMMANDS...] end

Description

The break 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.

Example

The following code searches all .c files for smurfs, and halts at the first occurrence.

for i in *.c
    if grep smurf $i
        echo Smurfs are present in $i
        break
    end
end

Back to index.


builtin - run a builtin command

Synopsis

builtin BUILTINNAME [OPTIONS...]

Description

Prefixing a command with the word 'builtin' forces fish to ignore any aliases with the same name.

Example

builtin jobs

causes fish to execute the jobs builtin, even if a function named jobs exists.

Back to index.


case - conditionally execute a block of commands

Synopsis

switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end

Description

The switch 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.

Example

If the variable $animal contains the name of an animal, the following code would attempt to classify it:

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 - change directory

Synopsis

cd [DIRECTORY]

Description Changes the current

directory. If 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 - set or get the current commandline buffer

Synopsis

commandline [OPTIONS] [CMD]

Description

The following switches change what the commandline builtin does

The following switches change the way commandline updates the commandline buffer

The following switches change what part of the commandline is printed or updated

The following switch changes the way commandline prints the current commandline buffer

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.

Example

commandline -j $history[3]

replaces the job under the cursor with the third item from the commandline history.

Back to index.


command - run a program

Synopsis

command COMMANDNAME [OPTIONS...]

Description

prefixing a command with the word 'command' forces fish to ignore any aliases or builtins with the same name.

Example

command ls

causes fish to execute the ls program, even if there exists a 'ls' alias.

Back to index.


complete - edit command specific tab-completions.

Synopsis

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]

Description

For an introduction to how to specify completions, see the section Writing your own completions of the fish manual.

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.

Example

The short 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 - test if a word is present in a list

Synopsis

contains [OPTIONS] KEY [VALUES...]

Description

Test if the set VALUES contains the string KEY. Return status is 0 if yes, 1 otherwise

Example

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.


continue - skip the rest of the current lap of the innermost currently evaluated loop

Synopsis

LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] end

Description

The continue 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.

Example

The following code removes all tmp files without smurfs.

for i in *.tmp
    if grep smurf $i
        continue
    end
    rm $i
end

Back to index.


count - count the number of elements of an array

Synopsis

count $VARIABLE

Description

count 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.

Example

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.


dirh - print directory history

Synopsis

dirh

Description

dirh prints the current directory history. The current position in the history is highlighted using $fish_color_history_current.

Back to index.


dirs - print directory stack

Synopsis

dirs

Description

dirs prints the current directory stack.

Back to index.


else - execute command if a condition is not met

Synopsis

if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end

Description

if 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.


case - conditionally execute a block of commands

Synopsis

switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end

Description

The switch 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.

Example

If the variable $animal contains the name of an animal, the following code would attempt to classify it:

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 - change directory

Synopsis

cd [DIRECTORY]

Description Changes the current

directory. If 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 - set or get the current commandline buffer

Synopsis

commandline [OPTIONS] [CMD]

Description

The following switches change what the commandline builtin does

The following switches change the way commandline updates the commandline buffer

The following switches change what part of the commandline is printed or updated

The following switch changes the way commandline prints the current commandline buffer

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.

Example

commandline -j $history[3]

replaces the job under the cursor with the third item from the commandline history.

Back to index.


command - run a program

Synopsis

command COMMANDNAME [OPTIONS...]

Description

prefixing a command with the word 'command' forces fish to ignore any aliases or builtins with the same name.

Example

command ls

causes fish to execute the ls program, even if there exists a 'ls' alias.

Back to index.


complete - edit command specific tab-completions.

Synopsis

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]

Description

For an introduction to how to specify completions, see the section Writing your own completions of the fish manual.

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.

Example

The short 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 - test if a word is present in a list

Synopsis

contains [OPTIONS] KEY [VALUES...]

Description

Test if the set VALUES contains the string KEY. Return status is 0 if yes, 1 otherwise

Example

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.


continue - skip the rest of the current lap of the innermost currently evaluated loop

Synopsis

LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] end

Description

The continue 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.

Example

The following code removes all tmp files without smurfs.

for i in *.tmp
    if grep smurf $i
        continue
    end
    rm $i
end

Back to index.


count - count the number of elements of an array

Synopsis

count $VARIABLE

Description

count 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.

Example

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.


dirh - print directory history

Synopsis

dirh

Description

dirh prints the current directory history. The current position in the history is highlighted using $fish_color_history_current.

Back to index.


dirs - print directory stack

Synopsis

dirs

Description

dirs prints the current directory stack.

Back to index.


else - execute command if a condition is not met

Synopsis

if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end

Description

if 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.


case - conditionally execute a block of commands

Synopsis

switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end

Description

The switch 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.

Example

If the variable $animal contains the name of an animal, the following code would attempt to classify it:

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 - change directory

Synopsis

cd [DIRECTORY]

Description Changes the current

directory. If 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 - set or get the current commandline buffer

Synopsis

commandline [OPTIONS] [CMD]

Description

The following switches change what the commandline builtin does

The following switches change the way commandline updates the commandline buffer

The following switches change what part of the commandline is printed or updated

The following switch changes the way commandline prints the current commandline buffer

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.

Example

commandline -j $history[3]

replaces the job under the cursor with the third item from the commandline history.

Back to index.


command - run a program

Synopsis

command COMMANDNAME [OPTIONS...]

Description

prefixing a command with the word 'command' forces fish to ignore any aliases or builtins with the same name.

Example

command ls

causes fish to execute the ls program, even if there exists a 'ls' alias.

Back to index.


complete - edit command specific tab-completions.

Synopsis

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]

Description

For an introduction to how to specify completions, see the section Writing your own completions of the fish manual.

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.

Example

The short 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 - test if a word is present in a list

Synopsis

contains [OPTIONS] KEY [VALUES...]

Description

Test if the set VALUES contains the string KEY. Return status is 0 if yes, 1 otherwise

Example

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.


continue - skip the rest of the current lap of the innermost currently evaluated loop

Synopsis

LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] end

Description

The continue 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.

Example

The following code removes all tmp files without smurfs.

for i in *.tmp
    if grep smurf $i
        continue
    end
    rm $i
end

Back to index.


count - count the number of elements of an array

Synopsis

count $VARIABLE

Description

count 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.

Example

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.


dirh - print directory history

Synopsis

dirh

Description

dirh prints the current directory history. The current position in the history is highlighted using $fish_color_history_current.

Back to index.


dirs - print directory stack

Synopsis

dirs

Description

dirs prints the current directory stack.

Back to index.


else - execute command if a condition is not met

Synopsis

if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end

Description

if 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.


case - conditionally execute a block of commands

Synopsis

switch VALUE; [case [WILDCARD...]; [COMMANDS...]; ...] end

Description

The switch 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.

Example

If the variable $animal contains the name of an animal, the following code would attempt to classify it:

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 - change directory

Synopsis

cd [DIRECTORY]

Description Changes the current

directory. If 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 - set or get the current commandline buffer

Synopsis

commandline [OPTIONS] [CMD]

Description

The following switches change what the commandline builtin does

The following switches change the way commandline updates the commandline buffer

The following switches change what part of the commandline is printed or updated

The following switch changes the way commandline prints the current commandline buffer

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.

Example

commandline -j $history[3]

replaces the job under the cursor with the third item from the commandline history.

Back to index.


command - run a program

Synopsis

command COMMANDNAME [OPTIONS...]

Description

prefixing a command with the word 'command' forces fish to ignore any aliases or builtins with the same name.

Example

command ls

causes fish to execute the ls program, even if there exists a 'ls' alias.

Back to index.


complete - edit command specific tab-completions.

Synopsis

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]

Description

For an introduction to how to specify completions, see the section Writing your own completions of the fish manual.

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.

Example

The short 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 - test if a word is present in a list

Synopsis

contains [OPTIONS] KEY [VALUES...]

Description

Test if the set VALUES contains the string KEY. Return status is 0 if yes, 1 otherwise

Example

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.


continue - skip the rest of the current lap of the innermost currently evaluated loop

Synopsis

LOOP_CONSTRUCT; [COMMANDS...;] continue; [COMMANDS...;] end

Description

The continue 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.

Example

The following code removes all tmp files without smurfs.

for i in *.tmp
    if grep smurf $i
        continue
    end
    rm $i
end

Back to index.


count - count the number of elements of an array

Synopsis

count $VARIABLE

Description

count 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.

Example

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.


dirh - print directory history

Synopsis

dirh

Description

dirh prints the current directory history. The current position in the history is highlighted using $fish_color_history_current.

Back to index.


dirs - print directory stack

Synopsis

dirs

Description

dirs prints the current directory stack.

Back to index.


else - execute command if a condition is not met

Synopsis

if CONDITION; COMMANDS_TRUE...; [else; COMMANDS_FALSE...;] end

Description

if 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