Ubuntu 安装 Zsh ,配置最强终端

Z shell(Zsh)是一款可用作交互式登录的 shell 及脚本编写的命令解释器。Zsh 对 Bourne shell 做出了大量改进,同时加入了 Bash、ksh 及 tcsh 的某些功能。

安装 Zsh

# 安装
sudo apt install zsh

# 将 zsh 设置为默认 shell
chsh -s /bin/zsh

# 检查
echo $SHELL
# 返回 /usr/bin/zsh 即表示成功;若没成功,重启试试看

安装 Oh My Zsh

Oh My Zsh is an open source, community-driven framework for managing your zsh configuration.

Oh My Zsh will not make you a 10x developer...but you may feel like one.

Oh My Zsh 是基于 Zsh 命令行的一个扩展工具集,提供了丰富的扩展功能,如:主题配置,插件机制,内置的便捷操作等,,可以给我们一种全新的命令行使用体验。[1]

% 通过 curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

% 或者 通过 wget
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

配置

更换主题

这里 选择喜欢的主题,将名称填入根目录 .zshrc 中对应位置

ZSH_THEME="theme name"

配置插件

在这里,我介绍我使用的 3 个插件,安装都很简单,打开 Terminal 依次输入

  1. 自动补全 zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  1. 代码高亮 zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  1. 快速打开 GitHub 仓库 git-open
git clone https://github.com/paulirish/git-open.git $ZSH_CUSTOM/plugins/git-open`

最后需要配置 plugins

plugins=(
 git
 zsh-autosuggestions
 zsh-syntax-highlighting
 git-open
)

alias 命令别名

同样在 .zshrc 中,可使用下方类似语法设置命令别名,实现快速输入

# alias
alias cls='clear'

alias ga='git add'
alias gc='git commit -m'
alias gp='git push'
alias go='git-open'

alias update='sudo apt update'
alias upgrade='sudo apt upgrade'
alias install='sudo apt install'


alias aremove='sudo apt autoremove'
alias remove='sudo apt remove'
alias aclean='sudo apt autoclean'
alias clean='sudo apt clean'

最后,source ~/.zshrc 使配置生效

update shortcodes
加载评论