LoginSignup
1
1

More than 5 years have passed since last update.

fish_right_prompt

Last updated at Posted at 2016-09-09

fish をイジイジしています。
プロンプトのカレント・ディレクトリの略記がイイですね。ああいうのは短い方が好みです。
でも zsh 好きとしては右側に表示させたいな、と……思ったら、サポートされていました

で、俺の~/.config/fish/functionsを見てやー。

fish_right_prompt.fish
function fish_right_prompt --description '右側にカレント・ディレクトリを表示'
  prompt_pwd
end
fish_prompt.fish
# ほとんどデフォルトです
function fish_prompt --description 'Write out the prompt'
  # Just calculate this once, to save a few cycles when displaying the prompt
  if not set -q __fish_prompt_hostname
    set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
  end

  set -l color_cwd
  set -l suffix
  switch $USER
  case root toor
    if set -q fish_color_cwd_root
      set color_cwd $fish_color_cwd_root
    else
      set color_cwd $fish_color_cwd
    end
    set suffix '#'
  case '*'
    set color_cwd $fish_color_cwd
    set suffix '>'
  end

  # (prompt_pwd) を消してます
  echo -n -s "$USER" @ "$__fish_prompt_hostname" ' ' (set_color $color_cwd) (set_color normal) "$suffix "
end

でまあ、こんな感じになるワケです。
名称未設定.jpg

git のブランチ表示はどうしようかなあ……。fish_configのサンプルはどれも今ひとつで……。

追記

これでイイや……。

fish_right_prompt.fish
function fish_right_prompt --description '右側に pwd と git status を表示'
  prompt_pwd
  __terlar_git_prompt
end

名称未設定.jpg
__terlar_git_prompt/usr/local/Cellar/fish/2.3.1/share/fish/functions/__terlar_git_prompt.fish で定義してあります。


追記の追記

version 2.7.2 に上げたら、なんか git status の表示がおかしくなったので、 __fish_git_prompt に変更……。

fish_right_prompt.fish
function fish_right_prompt --description '右側に pwd と git status を表示'
  prompt_pwd
  __fish_git_prompt
end
config.fish
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'

以下を参考にしました。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1