Ubuntu | 安裝oh-my-zsh



目錄


一、zsh說(shuō)明

  • zsh是一個(gè)Linux下強(qiáng)大的shell, 由于大多數(shù)Linux產(chǎn)品安裝以及默認(rèn)使用bash shell, 但是絲毫不影響極客們對(duì)zsh的熱衷, 幾乎每一款Linux產(chǎn)品都包含有zsh,通常可以用apt-get、urpmi或yum等包管理器進(jìn)行安裝.

  • zsh是bash的增強(qiáng)版,其實(shí)zsh和bash是兩個(gè)不同的概念,zsh更加強(qiáng)大。

  • 通常zsh配置起來(lái)非常麻煩,且相當(dāng)?shù)膹?fù)雜,所以oh-my-zsh是為了簡(jiǎn)化zsh的配置而開發(fā)的,因此oh-my-zsh算是zsh的配置.

  • Ubuntu16.0.4_Server_64_no_au_zsh

說(shuō)明:

參閱:oh-my-zsh


二、準(zhǔn)備

  • 查看系統(tǒng)當(dāng)前使用的shell
    echo $SHELL
  • 查看系統(tǒng)自帶哪些shell
    cat /etc/shells
  • oh-my-sh相關(guān)文件位置
  • vim ~/.zshrc

說(shuō)明:

  • ~表示用戶名目錄,<.FileName>表示隱藏文件.

三、安裝zsh

1. 開始安裝

apt install zsh -y

提示:

  • 查看系統(tǒng)自帶哪些shell
    cat /etc/shells

表明已經(jīng)安裝好zsh.

2. 配置

  • zsh設(shè)為默認(rèn)shell
    chsh -s /bin/zsh
    reboot

提示:

  • 若總是報(bào)錯(cuò)chsh: PAM: Authentication failure
    直接修改用戶的配置
    vim /etc/passwd/
  • 查看系統(tǒng)當(dāng)前使用的shell
    echo $SHELL

表明已經(jīng)將zsh設(shè)置為默認(rèn)shell.

  • 待解決問(wèn)題: 不知道為什么我的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 -)"


五、個(gè)性化


1. 主題

vim ~/.zshrc

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

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

注意:

  • 如果ZSH_THEME=""則不啟用任何主題.

  • 如果ZSH_THEME="random",那么每次打開一個(gè)新的終端窗口時(shí),電腦會(huì)隨機(jī)選擇一個(gè)主題使用,
    echo $RANDOM_THEME可輸出當(dāng)前主題名稱.

  • 如果你想從你最喜歡的主題列表中選擇隨機(jī)主題,那么ZSH_THEME="random"
    ZSH_THEME_RANDOM_CANDIDATES的值設(shè)置為你喜歡的主題名稱
    例如:
    ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )


2. 插件


  • 安裝incr自動(dòng)補(bǔ)全插件推薦

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

默認(rèn)開啟的插件,提供了大量 git 的alias.

  1. extract

功能強(qiáng)大的解壓插件,所有類型的文件解壓一個(gè)命令x全搞定,再也不需要去記tar后面到底是哪幾個(gè)參數(shù)了.

  1. z

強(qiáng)大的目錄自動(dòng)跳轉(zhuǎn)命令,會(huì)記憶你曾經(jīng)進(jìn)入過(guò)的目錄,用模糊匹配快速進(jìn)入你想要的目錄.


  • 安裝autojump自動(dòng)跳轉(zhuǎn)插件

apt install autojump
vi ~/.zshrc

. /usr/share/autojump/autojump.sh

source ~/.zshrc

提示:

  • 參閱:autojump1autojump2
  • 說(shuō)明文檔:cd /usr/share/doc/autojump/README.Debian
  • 軟件安裝位置:cd /usr/share/autojump

  • 安裝zsh-syntax-highlighting語(yǔ)法高亮插件

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語(yǔ)法歷史記錄插件

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. 更新

  • 設(shè)置更新日期
    vi ~/.zshrc
export UPDATE_ZSH_DAYS=13
  • 禁用自動(dòng)更新
    vi ~/.zshrc
DISABLE_AUTO_UPDATE="true"
  • 手動(dòng)更新oh-my-zsh
    upgrade_oh_my_zsh

2. 卸載

  • 卸載oh-my-zsh
    uninstall_oh_my_zsh zsh

3. (.zshrc)源文件內(nèi)容

# 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/Themes
ZSH_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.是否自動(dòng)更新
# 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-folder

4.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"

參閱:


更新中......


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。