fish shell 简要教程以及对bash的兼容性讨论。
本文的亮點在于兩點:1. 提出了一種fish與bash兼容性的臨時方案,2. 自己新建了一個屬于自己的fish主題。
fish的官網宣傳語是 Finally, a command line shell for the 90s。 翻譯過來就是 Fish shell 是一個為90后準備的 shell。有人說:“二逼青年用bash,普通青年用zsh,文藝青年用fish。”[4]
其次由于zsh 的速度實在是太慢了,所以決定換了fish, 簡單做下總結,發現還不錯。fish的智能提示非常強大。持續更新中,如果有好的建議或推薦歡迎評論。
文章同步在兩個平臺發布,轉載請注明來源:
簡書:https://www.jianshu.com/p/bf0...
segmentfault:https://segmentfault.com/a/11...
1 、ubuntu 安裝fish
sudo apt-add-repository ppa:fish-shell/release-2 sudo apt-get update sudo apt-get install fish #切換到fish sudo chsh -s /usr/bin/fish && fish其他平臺類似,可以根據官網說明來 [[1]](https://fishshell.com/)
fish的鮮明特征在于安裝時已經默認集成了很多需要的功能。
比如:
- 命令行語法高亮,錯誤會顯示紅色
- 智能提示
- 可以使用web網頁的進行終端配置
fish 有智能提示,一個命令一旦輸入過一次,會自動顯示上一次的全部命令,細心一點會發現會有一層灰色的字體表示上一次的命令,按Ctrl+F或者 右方向鍵→, 即可自動補全,如下圖。
2、 安裝autojump
git clone https://github.com/wting/autojump.git cd autojump ./install.pyvim ~/.config/fish/config.fish 按照install.py 命令給出的提示來修改config.fish, 添加 if test -f /home/ice/.autojump/share/autojump/autojump.fish; . /home/ice/.autojump/share/autojump/autojump.fish; end3、兼容性
由于fish 很多不兼容bash的功能導致了很多腳本無法運行,這一點是很多人吐槽fish的地方,我們需要一種方式來運行腳本。
比如
arc land --onto `git rev-parse --abbrev-ref HEAD`這條命令在fish里無法執行。
我們只需要在前面添加一個bash -c 命令即可,如下所示。
順手價格alias就更方便了,可以直接在命令行里使用命令arcl。
alias arcl bash -c "arc land --onto `git rev-parse --abbrev-ref HEAD`"對于腳本文件,比如我將需要執行的命令或文件放到repomerge.sh
在~/.config/fish/config.fish添加
alias up "bash -c /usr/bin/repomerge.sh"然后就可以自由的使用up命令了
4、網頁版fish
fish_config可以直接跳出網頁版本的界面。
web版本可以設置主題, 推薦其中的"Tomorrow Night"主題顏色。
選擇想要的主題,然后點擊set theme即可設置主題。
在命令里按enter 即可退出web版本的界面。
快速設置縮寫
5、插件管理
https://github.com/oh-my-fish...
omf install thefuck
雖然有fisher這個管理工具,但是目前還不穩定。
6、終端顯示git的分支名稱
在~/.config/fish/config.fish中添加如下代碼
function fish_prompt --description 'Write out the prompt'if not set -q __fish_prompt_normalset -g __fish_prompt_normal (set_color normal)end if not set -q __git_cbset __git_cb (set_color blue)" ("(set_color brred)(git branch ^/dev/null | grep \* | sed 's/* //')(set_color blue)")"end switch $USERcase rootif not set -q __fish_prompt_cwdif set -q fish_color_cwd_rootset -g __fish_prompt_cwd (set_color $fish_color_cwd_root)elseset -g __fish_prompt_cwd (set_color $fish_color_cwd)endendprintf '%s %s%s%s%s# ' $USER "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" $__git_cbcase '*' if not set -q __fish_prompt_cwdset -g __fish_prompt_cwd (set_color $fish_color_cwd)endprintf '%s %s%s%s%s ' $USER "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" $__git_cbend end樣式顯示如下:
其中function fish_prompt 函數用于定義fish終端的顯示樣式。
7、git 配置
# git 相關的配置 alias g "git" alias gst "git status" alias grs "git reset --soft" alias grh "git reset --hard" alias gb "git branch" alias gba "git branch -a" alias gl "git pull"8、配置自己的主題(終端顯示樣式)
我們只需要寫一個fish_prompt函數即可。集成了git的分支名稱以及當前的變化。
顯示的樣式如下:
**說明:
?代表當前git項目是干凈的。
%1 表示有一個文件未追蹤
+1 表示一個文件已暫存**
9、隱藏歡迎語
在confin.sh文件里添加如下函數即可
function fish_greeting end參考:
總結
以上是生活随笔為你收集整理的fish shell 简要教程以及对bash的兼容性讨论。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 实现和调用API接口
- 下一篇: 迭代器、生成器、装饰器