当前位置: 首页 > 工具软件 > oh-my-zsh > 使用案例 >

oh-my-zsh的安装

方璞
2023-12-01

oh-my-zsh的安装

在网上看见的一篇关于zsh安装以及配套的一些好用的插件的安装,怕以后找不到,自己记录下

一、啥是zsh

  • zsh相当于是bash的增强版,可以自定义安装好看的主体以及非常实用的插件
  • 但是zsh的安装非常麻烦,而oh-my-zsh应运而生,其诞生的目的就是为了简化zsh的安装

二、准备

  • 查看当前系统的默认shell
echo $SHELL
  • 查看系统自带了哪些shell
cat /etc/shells
  • oh-my-zsh的相关位置
    • 在主目录中,是隐藏文件,使用ls -la才能看见
  • 编辑oh-my-zsh的配置文件
    • vim ~/.zshrc

三、安装zsh

  1. 开始安装
sudo apt install zsh
安装后使用
cat /etc/shells
命令查看当前系统中全部shell中出现zsh则代表安装成功
  1. 配置
  • 设置zsh为默认shell
chsh -s /bin/zsh
reboot

四、安装oh-my-zsh

国内使用github实在太坑,我安装10次得有8次失败,所以建议使用国内的镜像
github

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

gitee

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

五、个性化

1. 主题

vim ~/.zshrc		//编辑zsh的配置文件

其中

ZSH_THEME="robbyrussell"

是默认主题,可以通过更改ZSH_THEME的值来进行切换主题
更改完成后保存退出并在终端输入指令

source ~/.zshrc

来使主题在终端中更新显示
原博主推荐的主题我也喜欢,所以也就没刻意去折腾了
主题名 AgnosterZak

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

更改配置文件 ZSH_THEME="agnosterzak"

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

注意

  • 如果ZSH_THEME=""则不启用任何主题
  • ZSH_THEME="random"那么每次打开终端都会随机选择一个主题使用,echo $RANDOM_THEME可以输出当前主题名称

2. 插件

  • 安装incr自动不全插件
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 ~/.zshrc
plugins=(git extract z)
source ~/.zshrc

第一个git是默认开启的插件,提供了大量的git alias
第二个extract是功能强大的解压插件,使用命令 x filename 即可解压压缩包,再也不用记tar后面的参数是什么了
第三个z是个强大的目录自动跳转命令,会记忆你曾经进入过的目录,用模糊匹配快速进入你想要的目录.使用 z 路径 即可

  • 安装语法高亮插件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

六、其他

1. 更新

  • 禁用自动更新
vim ~/.zshrc
DISABLE_AUTO_UPDATE="true"
  • 手动更新oh-my-zsh
    upgrade_oh_my_zsh

2. 卸载

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/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.是否自动更新
# 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"

转载地址:
https://www.jianshu.com/p/ba782b57ae96

 类似资料: