纵有疾风起
人生不言弃

Ubuntu | 安装oh-my-zsh


Ubuntu | 安装oh-my-zsh插图

目录

Ubuntu | 安装oh-my-zsh插图1

一、zsh说明

  • zsh是一个Linux下强大的shell, 由于大多数Linux产品安装以及默认使用bash shell, 但是丝毫不影响极客们对zsh的热衷, 几乎每一款Linux产品都包含有zsh,通常可以用apt-get、urpmi或yum等包管理器进行安装.

  • zsh是bash的增强版,其实zsh和bash是两个不同的概念,zsh更加强大。

  • 通常zsh配置起来非常麻烦,且相当的复杂,所以oh-my-zsh是为了简化zsh的配置而开发的,因此oh-my-zsh算是zsh的配置.

  • Ubuntu16.0.4_Server_64_no_au_zsh

说明:

参阅:oh-my-zsh


二、准备

  • 查看系统当前使用的shell
    echo $SHELL
Ubuntu | 安装oh-my-zsh插图2
  • 查看系统自带哪些shell
    cat /etc/shells
Ubuntu | 安装oh-my-zsh插图3
  • oh-my-sh相关文件位置
Ubuntu | 安装oh-my-zsh插图4
  • vim ~/.zshrc

说明:

  • ~表示用户名目录,<.FileName>表示隐藏文件.

三、安装zsh

1. 开始安装

apt install zsh -y

提示:

  • 查看系统自带哪些shell
    cat /etc/shells
Ubuntu | 安装oh-my-zsh插图5

表明已经安装好zsh.

2. 配置

  • zsh设为默认shell
    chsh -s /bin/zsh
    reboot

提示:

  • 若总是报错chsh: PAM: Authentication failure
    直接修改用户的配置
    vim /etc/passwd/
  • 查看系统当前使用的shell
    echo $SHELL
Ubuntu | 安装oh-my-zsh插图6

表明已经将zsh设置为默认shell.

  • 待解决问题: 不知道为什么我的root账户的用户名怎么变成了ubuntu?

四、安装oh-my-zsh

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"


五、个性化


1. 主题

vim ~/.zshrc

Ubuntu | 安装oh-my-zsh插图7

source ~/.zshrc

参阅:oh-my-zsh主题更多主题

cd ~/.oh-my-zsh/themes
wget https://raw.githubusercontent.com/zakaziko99/agnosterzak-ohmyzsh-theme/master/agnosterzak.zsh-theme
vi ~/.zshrc

agnosterzak
Ubuntu | 安装oh-my-zsh插图9

source ~/.zshrc
apt install fonts-powerline -y

注意:

  • 如果ZSH_THEME=""则不启用任何主题.

  • 如果ZSH_THEME="random",那么每次打开一个新的终端窗口时,电脑会随机选择一个主题使用,
    echo $RANDOM_THEME可输出当前主题名称.

  • 如果你想从你最喜欢的主题列表中选择随机主题,那么ZSH_THEME="random"
    ZSH_THEME_RANDOM_CANDIDATES的值设置为你喜欢的主题名称
    例如:
    ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )


2. 插件


  • 安装incr自动补全插件推荐
Ubuntu | 安装oh-my-zsh插图10

cd ~/.oh-my-zsh/plugins/
mkdir incr && cd incr
wget http://mimosa-pudica.net/src/incr-0.2.zsh
vi ~/.zshrc

source ~/.oh-my-zsh/plugins/incr/incr*.zsh

source ~/.zshrc

提示:

  • 与vim的提示相冲突的解决方案
$ vim t_arguments:451: _vim_files: function definition file not found

将~/.zcompdump*删除即可

rm -rf ~/.zcompdump*
exec zsh


  • 直接使用的插件推荐

vi ~/.zshrc

plugins=(git extract z)

source ~/.zshrc

  1. git

默认开启的插件,提供了大量 git 的alias.

  1. extract

功能强大的解压插件,所有类型的文件解压一个命令x全搞定,再也不需要去记tar后面到底是哪几个参数了.

Ubuntu | 安装oh-my-zsh插图11
  1. z

强大的目录自动跳转命令,会记忆你曾经进入过的目录,用模糊匹配快速进入你想要的目录.

Ubuntu | 安装oh-my-zsh插图12

  • 安装autojump自动跳转插件

apt install autojump
vi ~/.zshrc

. /usr/share/autojump/autojump.sh

source ~/.zshrc

提示:

  • 参阅:autojump1autojump2
  • 说明文档:cd /usr/share/doc/autojump/README.Debian
  • 软件安装位置:cd /usr/share/autojump

  • 安装zsh-syntax-highlighting语法高亮插件

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
source ~/.zshrc

提示:


  • 安装zsh-autosuggestions语法历史记录插件

git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
vim ~/.zshrc

plugins=(zsh-autosuggestions)最后一行:source $ZSH_CUSTOM/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

source ~/.zshrc

提示:

  • 参阅:zsh-autosuggestions
  • 软件安装位置:cd ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions

  • 其他

提示:


六、其他

1. 更新

  • 设置更新日期
    vi ~/.zshrc
export UPDATE_ZSH_DAYS=13
  • 禁用自动更新
    vi ~/.zshrc
DISABLE_AUTO_UPDATE="true"
  • 手动更新oh-my-zsh
    upgrade_oh_my_zsh

2. 卸载

  • 卸载oh-my-zsh
    uninstall_oh_my_zsh zsh

3. (.zshrc)源文件内容

# If you come from bash you might have to change your $PATH.# export PATH=$HOME/bin:/usr/local/bin:$PATH# Path to your oh-my-zsh installation.  export ZSH="/root/.oh-my-zsh"1.zsh主题# Set name of the theme to load --- if set to "random", it will# load a random theme each time oh-my-zsh is loaded, in which case,# to know which specific one was loaded, run: echo $RANDOM_THEME# See https://github.com/robbyrussell/oh-my-zsh/wiki/ThemesZSH_THEME="robbyrussell"# Set list of themes to pick from when loading at random# Setting this variable when ZSH_THEME=random will cause zsh to load# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/# If set to an empty array, this variable will have no effect.# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )# Uncomment the following line to use case-sensitive completion.# CASE_SENSITIVE="true"# Uncomment the following line to use hyphen-insensitive completion.# Case-sensitive completion must be off. _ and - will be interchangeable.# HYPHEN_INSENSITIVE="true"2.是否自动更新# Uncomment the following line to disable bi-weekly auto-update checks.# DISABLE_AUTO_UPDATE="true"3.更新周期# Uncomment the following line to change how often to auto-update (in days).# export UPDATE_ZSH_DAYS=13# Uncomment the following line to disable colors in ls.# DISABLE_LS_COLORS="true"# Uncomment the following line to disable auto-setting terminal title.# DISABLE_AUTO_TITLE="true"# Uncomment the following line to enable command auto-correction.# ENABLE_CORRECTION="true"# Uncomment the following line to display red dots whilst waiting for completion.# COMPLETION_WAITING_DOTS="true"# Uncomment the following line if you want to disable marking untracked files# under VCS as dirty. This makes repository status check for large repositories# much, much faster.# DISABLE_UNTRACKED_FILES_DIRTY="true"# Uncomment the following line if you want to change the command execution time# stamp shown in the history command output.# You can set one of the optional three formats:# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"# or set a custom format using the strftime function format specifications,# see 'man strftime' for details.# HIST_STAMPS="mm/dd/yyyy"# Would you like to use another custom folder than $ZSH/custom?# ZSH_CUSTOM=/path/to/new-custom-folder4.zsh插件# Which plugins would you like to load?# Standard plugins can be found in ~/.oh-my-zsh/plugins/*# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/# Example format: plugins=(rails git textmate ruby lighthouse)# Add wisely, as too many plugins slow down shell startup.plugins=(git)source $ZSH/oh-my-zsh.sh# User configuration# export MANPATH="/usr/local/man:$MANPATH"# You may need to manually set your language environment# export LANG=en_US.UTF-8# Preferred editor for local and remote sessions# if [[ -n $SSH_CONNECTION ]]; then#   export EDITOR='vim'# else#   export EDITOR='mvim'# fi# Compilation flags# export ARCHFLAGS="-arch x86_64"# ssh# export SSH_KEY_PATH="~/.ssh/rsa_id"# Set personal aliases, overriding those provided by oh-my-zsh libs,# plugins, and themes. Aliases can be placed here, though oh-my-zsh# users are encouraged to define aliases within the ZSH_CUSTOM folder.# For a full list of active aliases, run `alias`.## Example aliases# alias zshconfig="mate ~/.zshrc"# alias ohmyzsh="mate ~/.oh-my-zsh"

参阅:


更新中......


文章转载于:https://www.jianshu.com/p/ba782b57ae96

原著是一个有趣的人,若有侵权,请通知删除

未经允许不得转载:起风网 » Ubuntu | 安装oh-my-zsh
分享到: 生成海报

评论 抢沙发

评论前必须登录!

立即登录