https://wiki.archlinux.org/api.php?action=feedcontributions&user=%E3%81%AF%E3%81%A4%E3%81%9B&feedformat=atomArchWiki - User contributions [en]2024-03-29T06:25:15ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Fish&diff=406559Fish2015-10-24T02:34:10Z<p>はつせ: </p>
<hr />
<div>{{lowercase title}}<br />
[[Category:Command shells]]<br />
[[de:Fish]]<br />
[[ja:Fish]]<br />
[[ru:Fish]]<br />
'''fish''' (the '''friendly interactive shell''') is a user friendly command line shell intended mostly for interactive use.<br />
<br />
== Installation ==<br />
<br />
[[pacman|Install]] the {{Pkg|fish}} package from the [[official repositories]] for the stable version of the [http://fishshell.com/ mainstream fork] of the project.<br />
<br />
[[pacman|Install]] {{AUR|fish-shell-git}}{{Broken package link|{{aur-mirror|fish-shell-git}}}} from the [[AUR]] for the latest development version.<br />
<br />
[[pacman|Install]] {{AUR|fish-git}} from the [[AUR]] for the legacy version that was [http://www.mail-archive.com/fish-users@lists.sourceforge.net/msg02893.html discontinued] by its [https://github.com/liljencrantz original developer] in 2011.<br />
<br />
To make fish the default shell, run {{ic|chsh -s /usr/bin/fish}}.<br />
<br />
== Input/output ==<br />
<br />
=== File descriptors ===<br />
Like other shells, fish lets you redirect input/output streams. This is useful 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:<br />
<br />
* Standard input (FD 0), used for reading (keyboard by default).<br />
* Standard output (FD 1), used for writing (screen by default).<br />
* Standard error (FD 2), used for displaying errors and warnings (screen by default).<br />
<br />
=== Redirection ===<br />
Any file descriptor can be directed to other files through a mechanism called redirection:<br />
<br />
{{bc|''Redirecting standard input:''<br />
$ command < source_file<br />
<br />
''Redirecting standard output:''<br />
$ command > destination<br />
<br />
''Appending standard output to an existing file:''<br />
$ command >> destination<br />
<br />
''Redirecting standard error:''<br />
$ command ^ destination<br />
<br />
''Appending standard error to an existing file:''<br />
$ command ^^ destination}}<br />
<br />
You can use one of the following as {{ic|destination}}:<br />
<br />
* A filename (the output will be written to the specified file).<br />
* An {{ic|&}} followed by the number of another file descriptor. The output will be written to the other file descriptor.<br />
* An {{ic|&}} followed by a {{ic|-}} sign. The output will not be written anywhere.<br />
<br />
Examples:<br />
{{bc|''Redirecting standard output to a file:''<br />
$ command > destination_file.txt<br />
<br />
''Redirecting both standard output and standard error to the same file:''<br />
$ command > destination_file.txt ^ &1<br />
<br />
''Silencing standard output:''<br />
$ command > &-}}<br />
<br />
=== Piping ===<br />
<br />
You can redirect standard output of one command to standard input of the next command. This is done by separating the commands by the pipe character ({{ic|<nowiki>|</nowiki>}}). Example:<br />
<br />
cat example.txt | head<br />
<br />
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:<br />
<br />
$ command 2>| less<br />
<br />
This will run {{ic|command}} and redirect its standard error to the {{ic|less}} command.<br />
<br />
== Configuration ==<br />
<br />
User configurations for fish are located at {{ic|~/.config/fish/config.fish}}. Adding commands or functions to the file will execute/define them when opening a terminal, similar to {{ic|.bashrc}}.<br />
<br />
=== Web interface ===<br />
<br />
The fish prompt and terminal colors can be set with the interactive web interface:<br />
<br />
fish_config<br />
<br />
Selected settings are written to your personal configuration file. You can also view defined functions and your history.<br />
<br />
=== Prompt ===<br />
<br />
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}}:<br />
{{bc|<nowiki><br />
# fish git prompt<br />
set __fish_git_prompt_showdirtystate 'yes'<br />
set __fish_git_prompt_showstashstate 'yes'<br />
set __fish_git_prompt_showupstream 'yes'<br />
set __fish_git_prompt_color_branch yellow<br />
<br />
# Status Chars<br />
set __fish_git_prompt_char_dirtystate '⚡'<br />
set __fish_git_prompt_char_stagedstate '→'<br />
set __fish_git_prompt_char_stashstate '↩'<br />
set __fish_git_prompt_char_upstream_ahead '↑'<br />
set __fish_git_prompt_char_upstream_behind '↓'<br />
<br />
function fish_prompt<br />
set last_status $status<br />
set_color $fish_color_cwd<br />
printf '%s' (prompt_pwd)<br />
set_color normal<br />
printf '%s ' (__fish_git_prompt)<br />
set_color normal<br />
end<br />
</nowiki>}}<br />
<br />
=== Command completion ===<br />
<br />
fish can generate autocompletions from man pages. Completions are written to {{ic|~/.config/fish/generated_completions/}} and can be generated by calling:<br />
<br />
fish_update_completions<br />
<br />
You can also define your own completions in {{ic|~/.config/fish/completions/}}. See {{ic|/usr/share/fish/completions/}} for a few examples.<br />
<br />
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.<br />
<br />
=== /etc/profile and ~/.profile compatibility ===<br />
<br />
Since standard POSIX {{ic|sh}} syntax is not compatible with fish, fish will not be able to source {{ic|/etc/profile}} (and thus all {{ic|*.sh}} in {{ic|/etc/profile.d}}) and {{ic|~/.profile}}<br />
<br />
If you want fish to source those files, install {{Pkg|dash}} and add this line to your {{ic|config.fish}}:<br />
env -i HOME=$HOME dash -l -c printenv | sed -e '/PATH/s/:/ /g;s/=/ /;s/^/set -x /' | source<br />
<br />
an alternative variant will save you one executable invocation by using a builtin command:<br />
env -i HOME=$HOME dash -l -c 'export -p' | sed -e "/PATH/s/'//g;/PATH/s/:/ /g;s/=/ /;s/^export/set -x/" | source<br />
<br />
==Tips and Tricks==<br />
===History Substitution===<br />
Fish does not implement history substitution (e.g. {{ic|sudo !!}}), and the fish developers have said that they [http://fishshell.com/docs/current/faq.html#faq-history do not plan to]. Still, this is an essential piece of many users' workflow. Reddit user, [http://www.reddit.com/u/crossroads1112 crossroads1112], created a function that regains some of the functionality of history substitution and with another syntax. The function is on [https://gist.github.com/crossroads1112/77badb2c3455e23b873b github] and instructions are included as comments in it. There is a [https://gist.github.com/b-/981892a65837ab0a387e forked version] that is closer to the original syntax and allows for {{ic|command !!}} if you specify the command in the helper function.<br />
<br />
== Troubleshooting ==<br />
<br />
{{Accuracy|Changing the default shell should not interfere with the execution of shell scripts, so long as they begin with a proper [https://en.wikipedia.org/wiki/Shebang_%28Unix%29 shebang line].}}<br />
<br />
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:<br />
<br />
gnome-terminal -e fish<br />
<br />
With LilyTerm and other light terminal emulators that do not support setting the shell it would look like this:<br />
<br />
SHELL=/usr/bin/fish lilyterm<br />
<br />
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.<br />
<br />
To set fish as the shell started in tmux, put this into your {{ic|~/.tmux.conf}}:<br />
<br />
set-option -g default-shell "/usr/bin/fish"<br />
<br />
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.<br />
<br />
If you decide to set fish as your default shell, you may find that you no longer have very much in your path.<br />
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.<br />
<br />
{{bc|<br />
if status --is-login<br />
set PATH $PATH /usr/bin /sbin<br />
end<br />
}}<br />
<br />
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.<br />
<br />
=== su launching Bash ===<br />
<br />
If ''su'' starts with Bash (because Bash is the default shell), define a function in fish:<br />
$ funced su<br />
function su<br />
/bin/su --shell=/usr/bin/fish $argv<br />
end<br />
$ funcsave su<br />
<br />
=== Start X at login ===<br />
<br />
Add the following to the bottom of your {{ic|~/.config/fish/config.fish}}.<br />
<br />
{{bc|1=<nowiki><br />
# start X at login<br />
if status --is-login<br />
if test -z "$DISPLAY" -a $XDG_VTNR -eq 1<br />
exec startx -- -keeptty<br />
end<br />
end<br />
</nowiki>}}<br />
<br />
{{Note|See [https://github.com/fish-shell/fish-shell/issues/1772 this issue] for reasons why {{ic|startx}} requires the {{ic|-keeptty}} flag when using fish.}}<br />
<br />
== See also ==<br />
<br />
* http://fishshell.com/ - Home page<br />
* http://fishshell.com/docs/2.1/index.html - Documentation</div>はつせ