Difference between revisions of "Fish"

From ArchWiki
Jump to: navigation, search
(marking dead link found by bot)
m (typo)
(29 intermediate revisions by 14 users not shown)
Line 1: Line 1:
[[Category:Fish (English)]]
+
[[Category:Command shells]]
 
[[de:Fish]]
 
[[de:Fish]]
{{i18n|Fish}}
+
'''Fish''' is a user friendly commandline shell intended mostly for interactive use.
  
== Introduction ==
+
== Installation ==
'''fish''' is a user friendly commandline shell intended mostly for interactive use.
+
  
== Installation instructions ==
+
[[pacman|Install]] {{Pkg|fish}} from the [[official repositories]].
To install the package for fish using pacman (the package is in the community repo)
+
run:
+
# pacman -S fish
+
  
 
To verify that it has been installed you can run:
 
To verify that it has been installed you can run:
  $ less /etc/shells
+
  $ grep fish /etc/shells
  
If you wanted to make fish your default shell run:
+
If you wanted to make Fish your default shell run:
 
  $ chsh -s /usr/bin/fish
 
  $ chsh -s /usr/bin/fish
  
== Pacman and fish ==
+
== Input/output ==
Context-aware completions for pacman and makepkg are built into fish, since the policy of the fish development is to include all the existent
+
completions in the upstream tarball. The memory management is clever enough to avoid any negative impact on resources.
+
  
== Troubleshooting ==
+
=== File descriptors ===
In arch, there are a lot of shell scripts written for bash, and these have not been translated to fish. It is advisable not to set fish as your default shell because of this. The best option is to open your terminal emulator (gnome-terminal, konsole, sakura, etc...) with a command line option that executes fish. For most terminals this is the -e switch, so for example, to open gnome-terminal using fish, change your shortcut to use:
+
Like other shells, fish lets you redirect input/output streams. This is usefull when using text files to save programs output or errors, or when using text files as input. Most programs use three input/output streams, represented by numbers called file descriptors (FD). These are:
  
gnome-terminal -e fish
+
* Standard input (FD 0), used for reading (keyborad by default).
 +
* Standard output (FD 1), used for writing (screen by default).
 +
* Standard error (FD 2), used for displaying errors and warnings (screen by default).
  
Another option is to set fish as the default shell for the terminal in the terminal's configuration or for a terminal profile if your terminal emulator has a profiles feature. This is contrast to changing the default shell for the user which would cause the above mentioned problem.
+
=== Redirection ===
 +
Any file descriptor can be directed to other files through a mechanism called redirection:
  
To set fish as the shell started in tmux, put this into your .tmux.conf:
+
{{bc|''Redirecting standard input:''
 +
$ command < source_file
  
set-option -g default-shell "/usr/bin/fish"
+
''Redirecting standard output:''
 +
$ command > destination
  
Not setting fish as system wide default allows the arch scripts to run on startup, ensure the environment variables are set correctly, and generally reduces the issues associated with using a non-bash compatible terminal like fish. 
+
''Appending standard output to an existing file:''
 +
$ command >> destination
  
If you decide to set fish as your default shell, you may find that you no longer have very much in your path.
+
''Redirecting standard error:''
You can add a section to your ~/.config/fish/config.fish file that will set your path correctly on login. This is much like .profile or .bash_profile as it is only executed for login shells.
+
$ command ^ destination
  
if status --is-login
+
''Appending standard error to an existing file:''
    set PATH $PATH /usr/bin /sbin
+
$ command ^^ destination}}
end
+
  
Note that you will need to manually add various other environment variables, such as $MOZ_PLUGIN_PATH.  It is a huge amount of work to get a seamless experience with fish as your default shell.
+
You can use one of the following as {{ic|destination}}:
  
== Configuration Suggestions ==
+
* A filename (the output will be written to the specified file).
If you would like fish to display the branch and dirty status when you are in a git directory, you can add the following to your ~/.config/fish/config.fish:
+
* An {{ic|&}} followed by the number of another file descriptor. The output will be written to the other file descriptor.
 +
* An {{ic|&}} followed by a {{ic|-}} sign. The output will not be written anywhere.
  
set fish_git_dirty_color red
+
Examples:
function parse_git_dirty
+
{{bc|''Redirecting standard otput to a file:''
          git diff --quiet HEAD ^&-
+
$ command > destination_file.txt
          if test $status = 1
+
 
            echo (set_color $fish_git_dirty_color)"Δ"(set_color normal)
+
''Redirecting both standard output and standard error to the same file:''
          end
+
$ command > destination_file.txt ^ &1
  end
+
 
function parse_git_branch
+
''Silencing standard output:''
          # git branch outputs lines, the current branch is prefixed with a *
+
$ command > &-}}
          set -l branch (git branch --color ^&- | awk '/*/ {print $2}')
+
 
          echo $branch (parse_git_dirty)   
+
=== Piping ===
end
+
 
 +
You can redirect standard output of one command to standard input of the next command. This is done by separanting the commands by the pipe character ({{ic|<nowiki>|</nowiki>}}). Example:
 +
 
 +
cat example.txt | head
 +
 
 +
You can redirect other file descriptors to the pipe (besides standard output). The next example shows how to use standard error of one command as standard input of another command, prepending standard error file descriptor's number and {{ic|>}} to the pipe:
 +
 
 +
  $ command 2>| less
 +
 
 +
This will run {{ic|command}} and redirect it's standard error to the {{ic|less}} command.
 +
 
 +
== Configuration ==
 +
 
 +
If you would like Fish to display the branch and dirty status when you are in a git directory, you can add the following to your {{ic|~/.config/fish/config.fish}}:
 +
{{bc|<nowiki>
 +
# Fish git prompt
 +
set __fish_git_prompt_showdirtystate 'yes'
 +
set __fish_git_prompt_showstashstate 'yes'
 +
set __fish_git_prompt_showupstream 'yes'
 +
set __fish_git_prompt_color_branch yellow
 +
 
 +
# Status Chars
 +
set __fish_git_prompt_char_dirtystate '⚡'
 +
set __fish_git_prompt_char_stagedstate '→'
 +
set __fish_git_prompt_char_stashstate '↩'
 +
set __fish_git_prompt_char_upstream_ahead '↑'
 +
set __fish_git_prompt_char_upstream_behind '↓'
 
   
 
   
function fish_prompt
+
function fish_prompt
          if test -z (git branch --quiet 2>| awk '/fatal:/ {print "no git"}')
+
        set last_status $status
            printf '%s@%s %s%s%s (%s) $ ' (whoami) (hostname|cut -d . -f 1) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal) (parse_git_branch)           
+
        set_color $fish_color_cwd
          else
+
        printf '%s' (prompt_pwd)
            printf '%s@%s %s%s%s $ ' (whoami) (hostname|cut -d . -f 1) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
+
        set_color normal
          end
+
        printf '%s ' (__fish_git_prompt)
 +
      set_color normal
 +
end
 +
</nowiki>}}
 +
 
 +
If ''su'' starts with Bash (because Bash is the default shell), define a function in Fish:
 +
$  funced su
 +
function su
 +
        /bin/su --shell=/usr/bin/fish $argv
 
  end
 
  end
 +
$ funcsave su
  
If su starts with bash (because bash is the default shell), define a function in fish:
+
=== Pacman and Fish ===
~> funced su
+
 
  su> function su
+
Context-aware completions for Arch Linux-specific commands like ''pacman'', ''pacman-key'', ''makepkg'', ''cower'', ''pbget'', ''pacmatic'' are built into Fish, since the policy of the Fish development is to include all the existent completions in the upstream tarball. The memory management is clever enough to avoid any negative impact on resources.
        su --shell=/usr/bin/fish $argv
+
 
    end
+
== Troubleshooting ==
~> funcsave su
+
 
 +
In Arch, there are a lot of shell scripts written for Bash, and these have not been translated to Fish. It is advisable not to set Fish as your default shell because of this. The best option is to open your terminal emulator with a command line option that executes Fish. For most terminals this is the {{ic|-e}} switch, so for example, to open gnome-terminal using Fish, change your shortcut to use:
 +
 
 +
  gnome-terminal -e fish
 +
 
 +
With LilyTerm and other light terminal emulators that don't support setting the shell it would look like this:
 +
 
 +
SHELL=/usr/bin/fish lilyterm
 +
 
 +
Another option is to set Fish as the default shell for the terminal in the terminal's configuration or for a terminal profile if your terminal emulator has a profiles feature. This is contrast to changing the default shell for the user which would cause the above mentioned problem.
 +
 
 +
To set Fish as the shell started in tmux, put this into your {{ic|~/.tmux.conf}}:
 +
 
 +
set-option -g default-shell "/usr/bin/fish"
  
Some useful tab completion scripts that are not included into the official fish package:
+
Not setting Fish as system wide default allows the arch scripts to run on startup, ensure the environment variables are set correctly, and generally reduces the issues associated with using a non-Bash compatible terminal like Fish.
* [[anamnesis.fish]]
+
* [[bauerbill.fish]]
+
* [[duply.fish]]
+
* [[ln.fish]]
+
* [[shoutcast-search.fish]]
+
Patches to existing tab completions:
+
* [[makepkg.patch]]
+
* [[locate.patch]]
+
* [[pacman.patch]]
+
  
== Current state of fish development ==
+
If you decide to set Fish as your default shell, you may find that you no longer have very much in your path.
The original developer, Axel Liljencrantz has seemingly abandoned the project, the [http://fishshell.org/darcs/fish official darcs repository]{{Linkrot|2011|09|04}} hasn't been touched since March 2009. The rest of his team slowly took over and transferred the codebase to gitorius: http://gitorious.org/fish-shell
+
You can add a section to your {{ic|~/.config/fish/config.fish}} file that will set your path correctly on login. This is much like {{ic|.profile}} or {{ic|.bash_profile}} as it is only executed for login shells.
  
So far several bug fixes are available from the git repository. Also, there is an AUR package for the git master branch, which is considered stable for everyday use: [http://aur.archlinux.org/packages.php?ID=43684 fish-git].
+
{{bc|
 +
if status --is-login
 +
        set PATH $PATH /usr/bin /sbin
 +
end
 +
}}
  
Development has been [http://www.mail-archive.com/fish-users@lists.sourceforge.net/msg02540.html started again] on fish, don't expect big changes though in the near future.
+
Note that you will need to manually add various other environment variables, such as {{ic|$MOZ_PLUGIN_PATH}}. It is a huge amount of work to get a seamless experience with Fish as your default shell.
  
== Licenses ==
+
== Current state of Fish development ==
Fish Copyright (C) 2005-2006 Axel Liljencrantz.
+
  
Fish is released under the GNU General Public License, version 2.
+
The original developer, [https://github.com/liljencrantz Axel Liljencrantz] has [http://www.mail-archive.com/fish-users@lists.sourceforge.net/msg02893.html abandoned the project]. The rest of his team slowly took over and transferred the codebase to [http://gitorious.org/fish-shell gitorius].
  
Fish contains code under the BSD license, namely versions of the two functions strlcat and strlcpy, modified for use with wide character strings. This code is copyrighted by Todd C. Miller.
+
So far several bug fixes are available from the git repository. Also, there is an AUR package for the git master branch, which is considered stable for everyday use: {{AUR|fish-git}}.
  
The XSel command, written and copyrighted by Conrad Parker, is distributed together with, and used by fish. It is released under the MIT license.
+
On May 30, 2012 [http://ridiculousfish.com/shell/ ridiculous_fish] has [http://www.mailinglistarchive.com/html/fish-users@lists.sourceforge.net/2012-05/msg00004.html announced] a new fork of Fish which [http://www.mailinglistarchive.com/html/fish-users@lists.sourceforge.net/2012-05/msg00023.html has been adopted] as mainstream later, and development is now relocated to [https://github.com/fish-shell/fish-shell github]. The AUR package {{AUR|fish-shell-git}} follows the head branch of that, while the Fish package in the official repositories provides latest stable milestones as announced on the webpage.
  
The xdgmime library, written and copyrighted by Red Hat, Inc, is used by the mimedb command, which is a part of fish. It is released under the LGPL.
+
Ridiculous_fish has [http://ridiculousfish.com/blog/posts/fish_shell.html announced fish 2.0 stable version] at May 17th, 2013.
  
Fish contains code from the glibc library, namely the wcstok function. This code is licensed under the LGPL.
+
== See also ==
  
== External Links ==
+
* http://fishshell.com/ - Home page
*[http://www.fishshell.com HomePage]
+
* http://fishshell.com/docs/2.0/index.html - Documentation
*[http://www.fishshell.org/user_doc/index.html Documentation]{{Linkrot|2011|09|04}}
+

Revision as of 04:47, 26 November 2013

Fish is a user friendly commandline shell intended mostly for interactive use.

Installation

Install fish from the official repositories.

To verify that it has been installed you can run:

$ grep fish /etc/shells

If you wanted to make Fish your default shell run:

$ chsh -s /usr/bin/fish

Input/output

File descriptors

Like other shells, fish lets you redirect input/output streams. This is usefull when using text files to save programs output or errors, or when using text files as input. Most programs use three input/output streams, represented by numbers called file descriptors (FD). These are:

  • Standard input (FD 0), used for reading (keyborad by default).
  • Standard output (FD 1), used for writing (screen by default).
  • Standard error (FD 2), used for displaying errors and warnings (screen by default).

Redirection

Any file descriptor can be directed to other files through a mechanism called redirection:

Redirecting standard input:
$ command < source_file

Redirecting standard output:
$ command > destination

Appending standard output to an existing file:
$ command >> destination

Redirecting standard error:
$ command ^ destination

Appending standard error to an existing file:
$ command ^^ destination

You can use one of the following as destination:

  • A filename (the output will be written to the specified file).
  • An & followed by the number of another file descriptor. The output will be written to the other file descriptor.
  • An & followed by a - sign. The output will not be written anywhere.

Examples:

Redirecting standard otput to a file:
$ command > destination_file.txt

Redirecting both standard output and standard error to the same file:
$ command > destination_file.txt ^ &1

Silencing standard output:
$ command > &-

Piping

You can redirect standard output of one command to standard input of the next command. This is done by separanting the commands by the pipe character (|). Example:

cat example.txt | head

You can redirect other file descriptors to the pipe (besides standard output). The next example shows how to use standard error of one command as standard input of another command, prepending standard error file descriptor's number and > to the pipe:

$ command 2>| less

This will run command and redirect it's standard error to the less command.

Configuration

If you would like Fish to display the branch and dirty status when you are in a git directory, you can add the following to your ~/.config/fish/config.fish:

# Fish git prompt
set __fish_git_prompt_showdirtystate 'yes'
set __fish_git_prompt_showstashstate 'yes'
set __fish_git_prompt_showupstream 'yes'
set __fish_git_prompt_color_branch yellow

# Status Chars
set __fish_git_prompt_char_dirtystate '⚡'
set __fish_git_prompt_char_stagedstate '→'
set __fish_git_prompt_char_stashstate '↩'
set __fish_git_prompt_char_upstream_ahead '↑'
set __fish_git_prompt_char_upstream_behind '↓'
 
function fish_prompt
        set last_status $status
        set_color $fish_color_cwd
        printf '%s' (prompt_pwd)
        set_color normal
        printf '%s ' (__fish_git_prompt)
       set_color normal
end

If su starts with Bash (because Bash is the default shell), define a function in Fish:

$  funced su
function su
        /bin/su --shell=/usr/bin/fish $argv
end
$ funcsave su

Pacman and Fish

Context-aware completions for Arch Linux-specific commands like pacman, pacman-key, makepkg, cower, pbget, pacmatic are built into Fish, since the policy of the Fish development is to include all the existent completions in the upstream tarball. The memory management is clever enough to avoid any negative impact on resources.

Troubleshooting

In Arch, there are a lot of shell scripts written for Bash, and these have not been translated to Fish. It is advisable not to set Fish as your default shell because of this. The best option is to open your terminal emulator with a command line option that executes Fish. For most terminals this is the -e switch, so for example, to open gnome-terminal using Fish, change your shortcut to use:

gnome-terminal -e fish

With LilyTerm and other light terminal emulators that don't support setting the shell it would look like this:

SHELL=/usr/bin/fish lilyterm

Another option is to set Fish as the default shell for the terminal in the terminal's configuration or for a terminal profile if your terminal emulator has a profiles feature. This is contrast to changing the default shell for the user which would cause the above mentioned problem.

To set Fish as the shell started in tmux, put this into your ~/.tmux.conf:

set-option -g default-shell "/usr/bin/fish"

Not setting Fish as system wide default allows the arch scripts to run on startup, ensure the environment variables are set correctly, and generally reduces the issues associated with using a non-Bash compatible terminal like Fish.

If you decide to set Fish as your default shell, you may find that you no longer have very much in your path. You can add a section to your ~/.config/fish/config.fish file that will set your path correctly on login. This is much like .profile or .bash_profile as it is only executed for login shells.

if status --is-login
        set PATH $PATH /usr/bin /sbin
end

Note that you will need to manually add various other environment variables, such as $MOZ_PLUGIN_PATH. It is a huge amount of work to get a seamless experience with Fish as your default shell.

Current state of Fish development

The original developer, Axel Liljencrantz has abandoned the project. The rest of his team slowly took over and transferred the codebase to gitorius.

So far several bug fixes are available from the git repository. Also, there is an AUR package for the git master branch, which is considered stable for everyday use: fish-gitAUR.

On May 30, 2012 ridiculous_fish has announced a new fork of Fish which has been adopted as mainstream later, and development is now relocated to github. The AUR package fish-shell-gitAUR follows the head branch of that, while the Fish package in the official repositories provides latest stable milestones as announced on the webpage.

Ridiculous_fish has announced fish 2.0 stable version at May 17th, 2013.

See also