fish-shell

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
fish-shell [2019/01/21 10:37] – [リダイレクトとパイプ] mumeiyamibitofish-shell [2023/05/12 15:15] (現在) – [rsync や scp で fish をインストールしたリモートサーバにファイルを転送できない (旧方法)] mumeiyamibito
行 3: 行 3:
     * シェル言語の一つ     * シェル言語の一つ
     * zsh 並の補完機能がある     * zsh 並の補完機能がある
 +      * さらに予測機能 (tab を押さなくても履歴機能を表示) がある
     * 軽量     * 軽量
 +    * ''prevd''、''nextd''、''dirh'' コマンドで、カレントディレクトリ履歴を基に移動できる。
 +
 +===== インストール =====
 +  * 最新版をインストールする\\ <code bash>
 +$ sudo add-apt-repository ppa:fish-shell/release-3
 +$ sudo apt update
 +$ sudo apt install fish
 +</code>
 +
 +  * 共用サーバ等でホームディレクトリにインストールする ($HOME/local にインストールする場合)
 +    - cmake のバージョンが 3.2 以上でない場合、cmake をインストールする。
 +      * [[サーバ関連/cmake のインストール]] 
 +    - 最新版のソースをダウンロードする。\\ <code bash>
 +$ wget https://github.com/fish-shell/fish-shell/releases/download/3.1.2/fish-3.1.2.tar.gz
 +</code>
 +    - ソースを展開する。\\ <code bash>
 +$ tar axvf fish-3.1.2.tar.gz
 +</code>
 +    - インストールする。\\ <code bash>
 +$ cd fish-3.1.2/
 +$ cmake -DCMAKE_INSTALL_PREFIX=$HOME/local
 +$ make -j 4
 +$ make install
 +</code>
 +      * cmake の ''-DCMAKE_INSTALL_PREFIX'' オプションでインストール先を変える。
 +      * 参考サイト: [[http://physpolyglot.hateblo.jp/entry/2015/05/08/191110 | CMakeでprefixを変える - physpolyglot]]
 +      * ''-j 4'' は並列にコンパイルするオプションであり、この場合、4 CPU を使ってコンパイルしている。環境に応じて、変更する。
 +    - インストールされたか確認する。\\ <code bash>
 +$ ~/local/bin/fish --version
 +fish, version 3.1.2
 +</code>
 +    - .bashrc の末尾に追記する。\\ <code bash>
 +if [ "$SSH_TTY" != "" ]; then
 + BOOT_FISH=1
 + FISH_PATH=$HOME/local/bin/fish
 + if [ $BOOT_FISH -eq 1 ]; then
 + if [ -f $FISH_PATH ]; then
 + $FISH_PATH
 + exit
 + fi
 + fi
 +fi
 +</code>
 +      * ''chsh'' コマンドは ''/etc/shells'' に登録されていない shell を登録することができない。
 +        * 参考サイト: [[http://x68000.q-e-d.net/~68user/unix/pickup?%2Fetc%2Fshells | 設定ファイル:/etc/shells: UNIX/Linuxの部屋]]
 +      * ''BOOT_FISH'' が 1 のときのみ、fish-shell 環境になる。エディタで、ここを 1 以外にすれば、bash 環境になる。
 +      * bash が一度起動しているため、環境変数は引き継がれる。
 +      * rsync や scp が転送できない対策として、SSH_TTY の if 文を追加した (2020/10/26)。
 +        * 参考サイト: [[https://linux.just4fun.biz/?Linux%E7%92%B0%E5%A2%83%E8%A8%AD%E5%AE%9A/scp%E3%81%8C%E3%81%A7%E3%81%8D%E3%81%AA%E3%81%8F%E3%81%AA%E3%81%A3%E3%81%9F%E6%99%82%E3%81%AE%E5%AF%BE%E5%87%A6%E6%B3%95%E3%83%BBbashrc%E7%B7%A8#d1b1e007 | Linux環境設定/scpができなくなった時の対処法・bashrc編 - Linuxと過ごす]]
 +    - 再ログインする。
 +
  
 ===== 環境設定 ===== ===== 環境設定 =====
行 155: 行 207:
  
 ==== find コマンドの exec が使えない ==== ==== find コマンドの exec が使えない ====
-  * 対策: ''{}'' をシングルクォートで囲んで、最後に ''+'' を付ける。\\ 例: <code bash>$ find . -name '*.sh' -exec chmod +x '{}' +</code> +  * 対策1: ''{}'' をシングルクォートで囲んで、最後に ''+'' を付ける。\\ 例: <code bash>$ find . -name '*.sh' -exec chmod +x '{}' +</code> 
-  * 参考サイト: [[https://unix.stackexchange.com/questions/301225/find-exec-not-working-in-fish | find -exec not working in fish - Unix & Linux Stack Exchange]]+    * 参考サイト: [[https://unix.stackexchange.com/questions/301225/find-exec-not-working-in-fish | find -exec not working in fish - Unix & Linux Stack Exchange]] 
 +  * 対策2: find の結果を xargs で処理する。\\ 例: <code bash>$ find . -name '*.sh' | xargs chmod +x</code>
  
 ==== if 文で優先順位のある複数の条件を扱う ==== ==== if 文で優先順位のある複数の条件を扱う ====
行 180: 行 233:
   * 参考サイト: [[http://fish.rubikitch.com/begin/ | begin:一連のコードをまとめる【変数・リダイレクト・条件】]]   * 参考サイト: [[http://fish.rubikitch.com/begin/ | begin:一連のコードをまとめる【変数・リダイレクト・条件】]]
  
 +==== fish-shell を導入したリモートに rsync や scp でアクセスできない ====
 +  * 【症状】fish-shell を導入したリモートに rsync や scp でファイルを転送しようとすると以下のエラーメッセージが表示される\\ <code>
 +protocol version mismatch -- is your shell clean?
 +(see the rsync man page for an explanation)
 +rsync error: protocol incompatibility (code 2) at compat.c(178) [sender=3.1.2]
 +</code>
 +  * 【原因】リモートに ssh にログインした際に、標準出力 (リモートサーバの状況やグリーティングなど) されるものがある場合にエラーになるらしい (bash など他のシェルでも同様の原因の問題があるらしい)。
 +  * 【解決方法】
 +    * ログイン時に実行される ''config.fish'' から、標準出力 (''echo'' など) を削除、あるいはコメントアウトする。
 +    * ログイン時に実行される ''config.fish'' の標準出力部分を ''if status --is-interactive ... end'' ブロックで囲む。
 +      * 対話シェルの時のみ表示するようにする。
 +      * 例: \\ <code bash>
 +if status --is-interactive
 +    echo "test"
 +end
 +</code>
 +  * 参考サイト: [[https://github.com/fish-shell/fish-shell/issues/3473 | Rsync and sftp doesn't work when remote host uses fish shell · Issue #3473 · fish-shell/fish-shell]]
 +
 +
 +
 +==== コマンドラインスタック ====
 +  * とても役立つテクニックで、buffer stack とも呼ばれるらしい…。
 +    * 長いコマンドを打っている時に、ヘルプオプションを見たくなった時に便利。
 +    * 長いコマンドを打っている時に、やり忘れたコマンドを実行したくなった時に便利。
 +  * つまり、現在の入力中のコマンドを一時的に退避させる方法。
 +  * 方法: 
 +    * 以下の関数を ''$HOME/.config/fish/config.fish'' に記述する。\\ <code bash>
 +function push-line
 +  set cl (commandline)
 +  commandline -f repaint
 +  if test -n (string join $cl)
 +    set -g fish_buffer_stack $cl
 +    commandline ''
 +    commandline -f repaint
 + 
 +    function restore_line -e fish_postexec
 +      commandline $fish_buffer_stack
 +      functions -e restore_line
 +      set -e fish_buffer_stack
 +    end
 +  end
 +end
 +
 +function fish_user_key_bindings                                                                                        
 +    bind \cs push-line
 +end
 +</code>
 +    * 最後の ''bind ...'' でキーバインドを設定し、Ctrl + s で動作するようにしている。
 +  * 参考サイト: [[http://turanegaku.hateblo.jp/entry/2017/06/22/015349 | fish shellでコマンドラインスタック - つらねの日記]]
 +
 +
 +==== rsync や scp で fish をインストールしたリモートサーバにファイルを転送できない (旧方法) ====
 +  * ''.bashrc'' の先頭に記述する。\\ <code bash>
 +if [ -z "$PS1" ]; then
 + return
 +fi
 +</code>
 +    * .bashrc で何らかの処理がされている場合、scp や rsync が進行しないエラーが発生するため、.bashrc がこれらのコマンドで読み込まれた際、対話モードでない場合は即座に終了するようにする。
 +    * 参考サイト: [[https://qiita.com/montblanc18/items/b93fa4082e3bc2702a7f | .bashrc内にechoを入れておくとscpに失敗する - Qiita]]
 +
 +
 +==== ハイフンの入った文字列の置換ができない ====
 +  * 問題: ''string replace'' でハイフンの入ったパターンを置換できない。
 +  * 解決策: ''replace'' の後に ''--'' (ハイフン 2 つ) を入れる。
 +    * 例: <code bash>
 +$ string replace -- '-min' '' 'hoge-min.js'
 +hoge.js
 +</code>
 +
 +  * 参考サイト: [[https://github.com/fish-shell/fish-shell/issues/3416 | string command fails if input starts with a dash · Issue #3416 · fish-shell/fish-shell · GitHub]]
 ===== 参考サイト ===== ===== 参考サイト =====
   * [[http://fish.rubikitch.com/document-ja/ | fish2.4日本語ドキュメント:すぐ使える25の便利機能と実例]]   * [[http://fish.rubikitch.com/document-ja/ | fish2.4日本語ドキュメント:すぐ使える25の便利機能と実例]]
  
-{{tag>プログラミング}}+{{tag>プログラミング Linux サーバ}}
  
  • fish-shell.1548034621.txt.gz
  • 最終更新: 2019/01/21 10:37
  • by mumeiyamibito