zshの設定がカオスになってきたので、 数年前にも一度トライして諦めたfish-shell を最近になってまた使い始めた。
以前に比べて、できることが増えてるし、設定は楽だしで、しばらく使ってみようと思う。
macでのインストール
brewで一発。
1 |
brew install fish |
設定
$HOME/.config/fish を作って、config.fish を置く。
関数?定義した設定は、 $HOME/.config/fish/functions に置くのが常套手段?のようだ。
1 |
mkdir -p .config/fish/functions |
.config/fish/config.fish
alias の設定に = は不要。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
export LC_ALL=ja_JP.UTF-8 # bin path の設定 set -U fish_user_paths /bin /usr/bin /usr/local/bin /sbin /usr/sbin/ $fish_user_paths # node.js / nodebrew set fish_user_paths $HOME/.nodebrew/current/bin $HOME/bin $fish_user_paths ## for python export PYENV_ROOT="$HOME/.pyenv" set fish_user_paths $PYENV_ROOT/shims $fish_user_paths . (pyenv init - | psub) # alias alias rm 'rm -i' alias mv 'mv -i' alias cp 'cp -i' alias clean '\rm *~' alias less 'less -r' |
プロンプトの右端に情報表示 (こだわり!)
zsh を使い続けていた理由の一つがこれ。右端に情報表示ができること。
.config/fish/functions/fish_prompt.fish (左側の設定)
1 2 3 4 5 6 7 8 9 10 11 |
function fish_prompt --description 'Write out the prompt' set -l prompt_symbol '' switch "$USER" case root toor set prompt_symbol '#' case '*' set prompt_symbol '$' end set -l time (date +"%H:%M") echo -n -s "[" (set_color cyan) (prompt_hostname) (set_color normal) ":" $USER "@" $time "]" $prompt_symbol " " end |
[ホスト名:ユーザ名@時間]$ が表示される。
.config/fish/functions/ fish_right_prompt.fish (右側の設定)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# 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_showuntrackedfiles 'yes' set __fish_git_prompt_show_informative_status 'yes' set __fish_git_prompt_showcolorhints 'yes' function fish_right_prompt set -l home_escaped (echo -n $HOME | sed 's/\//\\\\\//g') set -l pwd (echo -n $PWD | sed "s/^$home_escaped/~/" | sed 's/ /%20/g') __fish_git_prompt echo -n -s "[" (set_color $fish_color_cwd) $pwd (set_color normal) "]" end |
gitのディレクトリじゃない時: [~/パス]
gitのディレクトリの時: (ブランチ名|状態の記号)[~/パス]
この設定だけで、冒頭のプロンプトが完成!