文章目录

  • 一、fish 入门使用
    • 1 、Ubuntu 安装fish
    • 2、 安装autojump
    • 3、网页配置fish
    • 4、插件管理
    • 5、git 配置
  • 二、兼容bash脚本
    • 隐藏欢迎语
      • 其他配置
    • 参考:
  • 三、 全部配置如下
    • 系列文章:

Fish的官网宣传语是 Finally, a command line shell for the 90s。 翻译过来就是 Fish shell 是一个为90后准备的 shell。
有人说:“二逼青年用bash,普通青年用zsh,文艺青年用fish。”[4]
其次由于zsh 的速度实在是太慢,所以决定换用fish,fish速度快,智能提示强大。

本文的亮点在于三点:

1、Fish的入门使用
2、与bash兼容性的方案
3、一个属于自己的Fish主题

Fish配置请参考:https://github.com/iceqing/linux-template-setting/blob/master/fish/config.fish

下面分别介绍

一、fish 入门使用

1 、Ubuntu 安装fish

apt-get install software-properties-common
sudo apt-add-repository ppa:fish-shell/release-2
sudo apt-get update
sudo apt-get install fish
#切换到fish
echo /usr/bin/fish | sudo tee -a /etc/shells
sudo chsh -s /usr/bin/fish && fish

其他平台类似,可以根据官网说明来 [1]
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

fish_config 可以直接跳出网页版本配置fish的界面。
web版本可以设置主题, 推荐其中的"Tomorrow Night"主题颜色。

选择想要的主题,然后点击set theme即可设置主题。
在命令里按enter 即可退出web版本的界面。

在prompt里面可以自己选择fish终端的主题。

4、插件管理

https://github.com/oh-my-fish/oh-my-fish

omf install thefuck

虽然有fisher这个管理工具,但是目前还不稳定。

5、git 配置

我们只需要配置alias 既可以满足日常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"

二、兼容bash脚本

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

比如

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命令了

#2 配置自己的终端
样式显示如下:


其中function fish_prompt 函数用于定义fish终端的显示样式。

我们只需要写一个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)")"endendif not set -q __fish_prompt_cwdset -g __fish_prompt_cwd (set_color $fish_color_cwd)endprintf '%s%s%s%s ' "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" $__git_cb
end

隐藏欢迎语

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

function fish_greeting
end

其他配置

alias l "ll"
alias dir "dde-file-manager . &"
alias docker "sudo docker"
alias apt "sudo apt"

参考:

  1. 官网
  2. fish 安装 https://launchpad.net/~fish-shell/+archive/ubuntu/release-2
  3. Fish shell 入门教程 (阮一峰) http://www.ruanyifeng.com/blog/2017/05/fish_shell.html
  4. 宇宙第一shell——fish入门 https://www.jianshu.com/p/7ffd9d1af788

三、 全部配置如下

# git配置
alias g "git"
alias gst "git status"
alias gb "git branch"
alias gba "git branch -a"
alias gl "git pull"
alias gp "git push"# 系统相关配置
alias l "ll"
alias dir "dde-file-manager . &"
alias docker "sudo docker"
alias apt "sudo apt"# 终端显示样式的配置
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)")"endendif not set -q __fish_prompt_cwdset -g __fish_prompt_cwd (set_color $fish_color_cwd)endprintf '%s%s%s%s ' "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" $__git_cb
end# 终端提示语配置
function fish_greeting
end# 判断是否是git仓库的工具函数
function git_is_repo --description 'Check if directory is a repository'test -d .gitor command git rev-parse --git-dir >/dev/null ^/dev/null
end

如果你喜欢在前面加上用户名称可以使用

printf '%s %s%s%s%s ' "$USER" "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" $__git_cb

替换掉上面的

printf '%s%s%s%s ' "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" $__git_cb

本文内容基于知识共享署名 4.0 国际许可协议进行许可

系列文章:

1. Fish Shell使用心得

2. Fish Shell 3.0 新功能

Fish Shell使用心得相关推荐

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

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

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

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

  3. fish shell 简要教程以及对bash的兼容性讨论。

    本文的亮点在于两点:1. 提出了一种fish与bash兼容性的临时方案,2. 自己新建了一个属于自己的fish主题. fish的官网宣传语是 Finally, a command line shell ...

  4. Fish Shell 使用笔记

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

  5. linux fish颜色配置,如何在 Linux 中安装、配置和使用 Fish Shell?

    (给Linux爱好者加星标,提升Linux技能) 英文:Magesh Maruthamuthu,翻译:Linux中国/MK linux.cn/article-10622-1.html 每个 Linux ...

  6. Fish shell 入门教程

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

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

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

  8. Centos7安装fish shell,介绍及使用

    第一步:yum安装fish shell root用户下执行命令: cd /etc/yum.repos.d/ wget http://download.opensuse.org/repositories ...

  9. 修改默认shell为fish shell

    修改Linux默认shell为fish shell 默认的 bash 在命令提示上没那么强大,所以将其换为 fish shell 官网 http://fishshell.com/ debian/dee ...

最新文章

  1. MongoDB之副本集
  2. Residual Networks
  3. dns组件能够删除后恢复
  4. Android app native代码性能分析
  5. LwIP应用开发笔记之四:LwIP无操作系统TFTP服务器
  6. (转)在MAC上查找和设置$JAVA_HOME
  7. Android开发常用命令
  8. 手机ufs测试软件,EFTech eMMC 5.1,UFS 3.0测试工具
  9. SteinerTree模板
  10. Silverlight显示滚动条
  11. mysql 添加权限和撤销权限的实例(亲测可行)
  12. DellaOS引导程序篇(完结)
  13. Ubuntu安装客户端RabbitVCS(svn管理)
  14. 个人博客重写,心路历程【尚未佩脱剑,转眼便江湖。愿历经千帆,归来仍是少年。】
  15. Python 报错Process finished with exit code -1073740791 (0xC0000409)解决方法
  16. 多元数量值函数积分学
  17. 我的爬虫 之 爬今日头条街拍图片
  18. wpf 悬浮窗口的实现
  19. 人工智能之父,你知道是谁吗?
  20. 不做人生规划,你离挨饿只有三天(转)

热门文章

  1. 从流水线工人到谷歌上班的程序媛。。。
  2. HCIA-存储虚拟化
  3. 这6种开源协议(GPL,LGPL,BSD,MIT,Apache)
  4. 小程序页面的生命周期(onload,onshow,onready,onhide,onunload)
  5. BZOJ4631: 踩气球
  6. 分类器的sklearn交叉验证之我的理解
  7. 04.终端安全技术资料
  8. k8s技术预研2--Kubernetes中的13项重要概念或术语
  9. 2019某行业CTF大赛题目复现——图片隐写
  10. 调用高德逆地理接口_PHP实现高德地图的地理/逆地理编码