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

仅仅用于软件推荐,不适合发求软件或软件使用问题方面的贴子
回复
头像
millenniumdark
论坛版主
帖子: 4159
注册时间: 2005-07-02 14:41
系统: Ubuntu 14.04 (Kylin)
联系:

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

#1

帖子 millenniumdark » 2013-11-01 11:29

很久以前用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
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

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

#2

帖子 eexpress » 2013-11-01 11:39

没啥bug了?
以前记得不完善。丢弃了。
● 鸣学
头像
millenniumdark
论坛版主
帖子: 4159
注册时间: 2005-07-02 14:41
系统: Ubuntu 14.04 (Kylin)
联系:

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

#3

帖子 millenniumdark » 2013-11-07 18:23

eexpress 写了:没啥bug了?
以前记得不完善。丢弃了。
改進了不少。
暫時沒碰到bug。
头像
suiang
帖子: 30
注册时间: 2013-04-28 1:30
系统: ubuntukylin13.10

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

#4

帖子 suiang » 2013-11-12 23:22

fish.png
:em06
头像
millenniumdark
论坛版主
帖子: 4159
注册时间: 2005-07-02 14:41
系统: Ubuntu 14.04 (Kylin)
联系:

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

#5

帖子 millenniumdark » 2013-11-15 19:59

suiang 写了:
fish.png
:em06

这个错误提示好帅,求码(虽然大概也能猜出怎么写,不过偶是伸手党
头像
gf0710020216
帖子: 66
注册时间: 2008-10-31 17:38
联系:

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

#6

帖子 gf0710020216 » 2014-01-03 9:20

suiang 写了:
fish.png
:em06
求配置 :em09
平生只做一件事,做自己喜欢做的事!
www.leafonsword.org
回复