本文的亮点在于两点: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; end

3、兼容性

由于fish 很多不兼容bash的功能导致了很多脚本无法运行,这一点是很多人吐槽fish的地方,我们需要一种方式来运行脚本。

比如

arc land --onto `git rev-parse --abbrev-ref HEAD` 

这条命令在fish里无法执行。
我们只需要在前面添加一个bash -c 命令即可,如下所示。

bash -c "arc land --onto `git rev-parse --abbrev-ref HEAD`"

顺手价格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 表示一个文件已暂存**

# 终端显示样式的配置
function fish_prompt --description 'Write out the prompt'if not set -q __fish_prompt_normalset -g __fish_prompt_normal (set_color normal)end __fish_git_prompt >/dev/null 2>&1if git_is_repoif not set -q __git_cbset __git_cb (set_color blue)" ("(set_color brred)(git branch | grep \* | sed 's/* //') (set_color -o bryellow)(__fish_git_prompt_informative_status)(set_color blue)")"endend if not set -q __fish_prompt_cwdset -g __fish_prompt_cwd (set_color $fish_color_cwd)end printf '%s%s%s%s ' "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" $__git_cb
end

9、隐藏欢迎语

在confin.sh文件里添加如下函数即可

function fish_greeting
end

参考:

  1. 官网
  2. fish 安装 https://launchpad.net/~fish-s...
  3. Fish shell 入门教程 (阮一峰) http://www.ruanyifeng.com/blo...
  4. 宇宙第一shell——fish入门 https://www.jianshu.com/p/7ff...

fish shell 简要教程以及对bash的兼容性讨论。相关推荐

  1. 打造最强终端之一:Fish shell简明教程

    原文地址:https://kxcblog.com 本系列文章包括3篇,主要分享我在后端开发过程中使用终端的一些经验和心得,分享fish shell使用,使用tmux终端复用管理会话.窗口,以及vim插 ...

  2. Fish shell 入门教程

    命令行是程序员的必备技能.图形界面虽然好看,解决问题还是要靠命令行. 命令行由 Shell 提供.各种命令通过 Shell,传递给操作系统的内核.学习命令行就是在学习 Shell. Shell 有好几 ...

  3. Fish Shell使用心得

    文章目录 一.fish 入门使用 1 .Ubuntu 安装fish 2. 安装autojump 3.网页配置fish 4.插件管理 5.git 配置 二.兼容bash脚本 隐藏欢迎语 其他配置 参考: ...

  4. Fish Shell 使用笔记

    安装Fish Shell brew install fish 安装Oh My Fish curl -L https://get.oh-my.fish | fish 安装Fisher curl http ...

  5. mac fish shell的安装和使用教程

    补充说明 -----–以下记录于 2018.06.27-----– 1.fish中文文档: https://wiki.archlinux.org/index.php/Fish_(%E7%AE%80%E ...

  6. 从零开始的linux_manjaro+vim+fish shell+i3酷炫操作和配置(持续更新中......)

    本博客最新更新于 2021年11月18日 一.前言 笔者此前几乎没有vim使用经验,也没有安装过linux虚拟机,偶然在b站上看到TheCW的视频,遂惊异于linux和vim配合的巧妙与vim配置和f ...

  7. shell中竖线的作用_如何在 Linux 中安装、配置和使用 Fish Shell?

    每个 Linux 管理员都可能听到过 shell 这个词.你知道什么是 shell 吗? 你知道 shell 在 Linux 中的作用是什么吗? Linux 中有多少个 shell 可用? -- Ma ...

  8. linux中的shell有printf吗,Linux Shell系列教程之(八)Shell printf命令详解

    在上一篇:Linux Shell系列教程之(七)Shell输出这篇文章中,已经对Shell printf命令有了一个简略的介绍,本篇给大家详细介绍下Shell中的printf命令. 一.Shell p ...

  9. linux使用shell函数扩充命令,Linux Shell系列教程之(十五) Shell函数简介 | Linux大学...

    摘要 函数可以将一个复杂功能划分成若干模块,从而使程序结构更加清晰,代码重复利用率更高. 高级语言都支持函数,Shell也不例外.今天就为大家介绍下Shell中函数相关用法. 函数可以将一个复杂功能划 ...

最新文章

  1. swift(一)基础变量类型
  2. java oralce merge_mybatis 使用oracle merge into 语句踩坑实录(示例代码)
  3. CAPEX与OPEX
  4. 最新全球权威AI基准测试榜单:浪潮和NVIDIA霸榜了
  5. 查询在一张表不在另外一张表的记录
  6. rman backup database force 功能
  7. [剑指Offer] 数据流中的中位数
  8. Integer.parseInt() 与 Integer.valueOf() 区别
  9. [PAT乙级]1019 数字黑洞
  10. MySQL流浪记(五)—— MySQL中常见函数的使用(笔记)
  11. 22个开源的PHP框架
  12. linux常用解压命令总结
  13. Qt 信号槽的应用(二)
  14. 【SDE】随机微分方程(1)
  15. CSS实现选中图片效果
  16. Python的三目表达式and简短语法
  17. ios描述文件安装的问题
  18. 轻量级 android模拟器,【分享中控】轻量级中控系统
  19. Python 百分号打头的行命令
  20. 硬件设计3---什么是电容?

热门文章

  1. 关于数论【康托展开及其逆运算】
  2. 【转】Linux查看物理CPU个数、核数、逻辑CPU个数
  3. Omi框架学习之旅 - 插件机制之omi-touch 及原理说明
  4. 工作中git 操作汇总
  5. angularJs 跨控制器与跨页面传值
  6. Stream 与 byte[] 互转
  7. 只有失去了,才知道珍惜!!!
  8. 联机重做日志的配置过程
  9. 【转】Struts2 和 Spring MVC对比
  10. .Net运行时的相互关系