「Fish」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
1行目: 1行目:
 
{{lowercase title}}
 
{{lowercase title}}
[[Category:Command shells]]
+
[[Category:コマンドシェル]]
 
[[de:Fish]]
 
[[de:Fish]]
 
[[en:Fish]]
 
[[en:Fish]]
 
[[ru:Fish]]
 
[[ru:Fish]]
'''fish''' ('''friendly interactive shell''')は主に対話的に使用することを意図されたユーザフレンドリーなコマンドラインシェルです。
+
'''fish''' ('''friendly interactive shell''') は主に対話的に使用することを意図されたユーザフレンドリーなコマンドラインシェルです。
   
 
== インストール ==
 
== インストール ==
   
[[公式リポジトリ]]より、[http://fishshell.com/ 主流fork]の安定版{{Pkg|fish}}パッケージを[[pacman|インストール]]できます。
+
[[公式リポジトリ]]より、[http://fishshell.com/ 主流フォーク] の安定版 {{Pkg|fish}} パッケージを[[pacman|インストール]]できます。
   
最新の開発版は[[AUR]]より {{AUR|fish-shell-git}}{{Broken package link|{{aur-mirror|fish-shell-git}}}}を[[pacman|インストール]]します。
+
最新の開発版は [[AUR]] より {{AUR|fish-shell-git}}{{Broken package link|{{aur-mirror|fish-shell-git}}}} を[[pacman|インストール]]します。
   
2011年に[https://github.com/liljencrantz オリジナルの開発者]によって[http://www.mail-archive.com/fish-users@lists.sourceforge.net/msg02893.html 中止された]従来のバージョンは[[AUR]]より
+
2011年に [https://github.com/liljencrantz オリジナルの開発者] によ[http://www.mail-archive.com/fish-users@lists.sourceforge.net/msg02893.html 開発が中止された] 従来のバージョンは [[AUR]] より {{AUR|fish-git}} を[[pacman|インストール]]します。
{{AUR|fish-git}}を[[pacman|インストール]]します。
 
   
fishをデフォルトシェルにするには、{{ic|chsh -s /usr/bin/fish}}を実行します。
+
fish をデフォルトシェルにするには、{{ic|chsh -s /usr/bin/fish}} を実行します。
   
 
== 入出力 ==
 
== 入出力 ==
72行目: 71行目:
 
This will run {{ic|command}} and redirect its standard error to the {{ic|less}} command.
 
This will run {{ic|command}} and redirect its standard error to the {{ic|less}} command.
   
== Configuration ==
+
== 設定 ==
   
 
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}}.
 
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}}.
   
  +
=== ウェブインターフェイス ===
=== Web interface ===
 
   
 
The fish prompt and terminal colors can be set with the interactive web interface:
 
The fish prompt and terminal colors can be set with the interactive web interface:
113行目: 112行目:
 
=== コマンド補完 ===
 
=== コマンド補完 ===
   
fishはmanページより自動補完を生成できます。{{ic|~/.config/fish/generated_completions/}} に補完が書き込まれており、以下を呼び出すことによって生成することができます
+
fish man ページから自動補完を生成できます。{{ic|~/.config/fish/generated_completions/}} に補完が書き込まれており、以下を呼び出すことによって生成することができます:
   
 
fish_update_completions
 
fish_update_completions
   
また、独自の補完を {{ic|~/.config/fish/completions/}}に定義できます。{{ic|/usr/share/fish/completions/}}でいくつかの例を見ることができ
+
また、独自の補完を {{ic|~/.config/fish/completions/}} に定義できます。{{ic|/usr/share/fish/completions/}} でいくつかの例を見ることができます
   
fish開発のポリシーが上流のtarballに存在する補完を全て含以来、''pacman'', ''pacman-key'', ''makepkg'', ''cower'', ''pbget'', ''pacmatic''のようなArch Linux固有のコマンドのための文脈補完fishに含まれています。メモリ管理、リソースへの悪影響を回避すのに十分賢いです
+
fish開発のポリシーが上流の tarball に存在する補完を全て含めるというものなの ''pacman'', ''pacman-key'', ''makepkg'', ''cower'', ''pbget'', ''pacmatic'' どの Arch Linux 固有のコマンドの文脈に沿った補完fish に含まれています。メモリ管理が賢いために、リソース悪影響を与えことはありません
   
=== /etc/profile and ~/.profile compatibility ===
+
=== /etc/profile ~/.profile の互換性 ===
   
 
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}}
 
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}}
136行目: 135行目:
   
 
== トラブルシューティング ==
 
== トラブルシューティング ==
 
{{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].}}
 
   
 
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:
 
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:
166行目: 163行目:
 
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.
 
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.
   
=== suでbashが起動 ===
+
=== su bash が起動する ===
   
もし、suでbashが起動する場合(Bashがデフォルトシェルのため), fishに関数を定義します。
+
su bash が起動する場合 (Bash がデフォルトシェルのため)fish に関数を定義してください:
   
 
$ funced su
 
$ funced su
176行目: 173行目:
 
$ funcsave su
 
$ funcsave su
   
=== ログイン時にXを起動 ===
+
=== ログイン時に X を起動 ===
   
{{ic|~/.config/fish/config.fish}}の一番下に以下を追加します
+
{{ic|~/.config/fish/config.fish}} の一番下に以下を追加します:
   
 
{{bc|1=<nowiki>
 
{{bc|1=<nowiki>
189行目: 186行目:
 
</nowiki>}}
 
</nowiki>}}
   
{{Note|fish使用時に{{ic|startx}}が{{ic|-keeptty}}フラグを必要とする理由については[https://github.com/fish-shell/fish-shell/issues/1772 この記事]を参照してください。}}
+
{{Note|fish 使用時に {{ic|startx}} {{ic|-keeptty}} フラグを必要とする理由については [https://github.com/fish-shell/fish-shell/issues/1772 この記事] を参照してください。}}
   
 
== 参照 ==
 
== 参照 ==

2015年10月24日 (土) 20:41時点における版

fish (friendly interactive shell) は主に対話的に使用することを意図されたユーザフレンドリーなコマンドラインシェルです。

インストール

公式リポジトリより、主流フォーク の安定版 fish パッケージをインストールできます。

最新の開発版は AUR より fish-shell-gitAUR[リンク切れ: アーカイブ: aur-mirror]インストールします。

2011年に オリジナルの開発者 による 開発が中止された 従来のバージョンは AUR より fish-gitAURインストールします。

fish をデフォルトシェルにするには、chsh -s /usr/bin/fish を実行します。

入出力

File descriptors

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:

  • Standard input (FD 0), used for reading (keyboard 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).

リダイレクト

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 output 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 > &-

パイプ

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 (|). 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 its standard error to the less command.

設定

User configurations for fish are located at ~/.config/fish/config.fish. Adding commands or functions to the file will execute/define them when opening a terminal, similar to .bashrc.

ウェブインターフェイス

The fish prompt and terminal colors can be set with the interactive web interface:

fish_config

Selected settings are written to your personal configuration file. You can also view defined functions and your history.

プロンプト

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

コマンド補完

fish は man ページから自動補完を生成できます。~/.config/fish/generated_completions/ に補完が書き込まれており、以下を呼び出すことによって生成することができます:

fish_update_completions

また、独自の補完を ~/.config/fish/completions/ に定義できます。/usr/share/fish/completions/ でいくつかの例を見ることができます。

fish の開発元のポリシーが、上流の tarball に存在する補完を全て含めるというものなので pacman, pacman-key, makepkg, cower, pbget, pacmatic などの Arch Linux 固有のコマンドの文脈に沿った補完も fish に含まれています。メモリ管理が賢いために、リソースに悪影響を与えることはありません。

/etc/profile と ~/.profile の互換性

Since standard POSIX sh syntax is not compatible with fish, fish will not be able to source /etc/profile (and thus all *.sh in /etc/profile.d) and ~/.profile

If you want fish to source those files, install dash and add this line to your config.fish:

env -i HOME=$HOME dash -l -c printenv | sed -e '/PATH/s/:/ /g;s/=/ /;s/^/set -x /' | source

an alternative variant will save you one executable invocation by using a builtin command:

env -i HOME=$HOME dash -l -c 'export -p' | sed -e "/PATH/s/'//g;/PATH/s/:/ /g;s/=/ /;s/^export/set -x/" | source

Tips and Tricks

History Substitution

Fish does not implement history substitution (e.g. sudo !!), and the fish developers have said that they do not plan to. Still, this is an essential piece of many users' workflow. Reddit user, crossroads1112, created a function that regains some of the functionality of history substitution and with another syntax. The function is on github and instructions are included as comments in it. There is a forked version that is closer to the original syntax and allows for command !! if you specify the command in the helper function.

トラブルシューティング

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 do not 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.

su で bash が起動する

su で bash が起動する場合 (Bash がデフォルトシェルのため)、fish に関数を定義してください:

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

ログイン時に X を起動

~/.config/fish/config.fish の一番下に以下を追加します:

# start X at login
if status --is-login
    if test -z "$DISPLAY" -a $XDG_VTNR -eq 1
        exec startx -- -keeptty
    end
end
ノート: fish 使用時に startx-keeptty フラグを必要とする理由については この記事 を参照してください。

参照