分页: 1 / 1

推薦下fish 2 (順便分享fish_prompt)

发表于 : 2013-11-01 11:29
millenniumdark
很久以前用fish,後來轉回bash。

現在用了下 fish 2,感覺改善好多。

以前很多程序都帶bash和 zsh的tab補全,fish沒有,得自己寫,麻煩。現在`fish_update_completions` 可以自動根據 man 生成 tab補全。

新增的 auto suggestion 功能也很贊。

分享一下我的fish提示符,(是的,fish 2已經支持像 zsh 一樣的左右提示符了。)

左邊的保持簡潔,學習rc用

代码: 全选

;
作提示符,這樣複製的時候複製了提示符命令也不會出錯。
上一個命令exit不爲0的時候用紅色提醒。

代码: 全选

function fish_prompt
                 set --local last_status $status
                 set --local red (set_color -o red)
                 if test $last_status -ne 0
                     set error_exit "$red($last_status) "
                 end
                 echo -n "$error_exit; "
                 z --add "$PWD"
             end
當前目錄的信息放右邊,避免分散注意力。
還有git的branch名稱,以及是否有髒文件

代码: 全选

function fish_right_prompt
                       
                       if not set -q -g __fish_robbyrussell_functions_defined
                           set -g __fish_robbyrussell_functions_defined
                           function _git_branch_name
                               echo (git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
                           end
                           
                           function _is_git_dirty
                               echo (git status -s --ignore-submodules=dirty ^/dev/null)
                           end
                       end
                       
                       set -l cyan (set_color -o cyan)
                       set -l yellow (set_color -o yellow)
                       set -l red (set_color -o red)
                       set -l blue (set_color -o blue)
                       set -l normal (set_color normal)
                       
                       set -l arrow "$cyan➜ "
                       set -l cwd $normal(prompt_pwd)
                       
                       if [ (_git_branch_name) ]
                           set -l git_branch $blue(_git_branch_name)
                           set git_info "$blue ($git_branch$blue)"
                           
                           if [ (_is_git_dirty) ]
                               set -l dirty "$yellow ✗"
                               set git_info "$git_info$dirty"
                           end
                       end
                       
                       echo -n -s $arrow ' '$cwd $git_info $normal ' '
                   end

Re: 推薦下fish 2 (順便分享fish_prompt)

发表于 : 2013-11-01 11:39
eexpress
没啥bug了?
以前记得不完善。丢弃了。

Re: 推薦下fish 2 (順便分享fish_prompt)

发表于 : 2013-11-07 18:23
millenniumdark
eexpress 写了:没啥bug了?
以前记得不完善。丢弃了。
改進了不少。
暫時沒碰到bug。

Re: 推薦下fish 2 (順便分享fish_prompt)

发表于 : 2013-11-12 23:22
suiang
fish.png
:em06

Re: 推薦下fish 2 (順便分享fish_prompt)

发表于 : 2013-11-15 19:59
millenniumdark
suiang 写了:
fish.png
:em06

这个错误提示好帅,求码(虽然大概也能猜出怎么写,不过偶是伸手党

Re: 推薦下fish 2 (順便分享fish_prompt)

发表于 : 2014-01-03 9:20
gf0710020216
suiang 写了:
fish.png
:em06
求配置 :em09