Fish Shell使用心得
本文的亮点在于三点: 1、Fish的入门使用 Fish配置请参考:https://github.com/iceqing/linux-template-setting/blob/master/fish/config.fish 下面分别介绍 一、fish 入门使用1 、ubuntu 安装fishapt-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 有智能提示,一个命令一旦输入过一次,会自动显示上一次的全部命令,细心一点会发现会有一层灰色的字体表示上一次的命令,按
智能提示
2、 安装autojumpgit clone https://github.com/wting/autojump.git
cd autojump
./install.py
vim ~/.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
image.png
选择想要的主题,然后点击set theme即可设置主题。 在prompt里面可以自己选择fish终端的主题。
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 "arc land --onto `git rev-parse --abbrev-ref HEAD`"
顺手加个alias就更方便了,可以直接在命令行里使用命令 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命令了 配置自己的终端样式显示如下:
image.png
其中function fish_prompt 函数用于定义fish终端的显示样式。 我们只需要写一个fish_prompt函数即可。集成了git的分支名称以及当前的变化。 显示的样式如下:
image.png
说明: # 终端显示样式的配置
function fish_prompt --description ‘Write out the prompt‘
if not set -q __fish_prompt_normal
set -g __fish_prompt_normal (set_color normal)
end
__fish_git_prompt >/dev/null 2>&1
if git_is_repo
if not set -q __git_cb
set __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)")"
end
end
if not set -q __fish_prompt_cwd
set -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
隐藏欢迎语在confin.sh文件里添加如下函数即可 function fish_greeting
end
其他配置alias l "ll"
alias dir "dde-file-manager . &"
alias docker "sudo docker"
alias apt "sudo apt"
参考:
全部配置如下# 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"
# 系统相关配置
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_normal
set -g __fish_prompt_normal (set_color normal)
end
__fish_git_prompt >/dev/null 2>&1
if git_is_repo
if not set -q __git_cb
set __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)")"
end
end
if not set -q __fish_prompt_cwd
set -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
# 终端提示语配置
function fish_greeting
end
# 判断是否是git仓库的工具函数
function git_is_repo --description ‘Check if directory is a repository‘
test -d .git
or 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 国际 (CC BY-SA 4.0),转载请注明出处。 系列文章1. Fish Shell使用心得 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |