zsh/oh_my_zsh

zsh/oh_my_zsh配置(debian13)

如果bash的脚本开头是以!#/bin/bash的话,在zsh下完全兼容bash,其余的我就不知道鸟

注意以下所有指令均在debian系下运行

zsh

查看shell

1
echo $SHELL

安装zsh

1
2
sudo apt update
sudo apt install zsh

设置默认shell

  • 为sudo用户设置
1
sudo chsh -s /bin/zsh
  • 为特定用户
1
2
sudo chsh -s /bin/zsh <username>
# <username> 替换为实际用户名

oh_my_zsh

安装git

1
2
sudo apt update
sudo apt install git

自动安装

1
sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

也可以手动自行去github上克隆安装,然后将配置cp到自己的.zshrc上

  • 进阶

功能介绍:优雅主题、自动补全、语法高亮、esc两次等于添加sudo

主题

祖传powerlevel10k,

1
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

~/.zshrc中配置ZSH_THEME="powerlevel10k/powerlevel10k"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH

# Path to your Oh My Zsh installation.
export ZSH="$HOME/.oh-my-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/ohmyzsh/ohmyzsh/wiki/Themes
# ZSH_THEME="robbyrussell"
ZSH_THEME="powerlevel10k/powerlevel10k"

source .zshrc一下

plus

找到plugin再添加如下配置(还可以自己补充,不过以下三条足以)

zsh-autosuggestion::

1
git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-autosuggestions

zsh-syntax-highlighting:

1
git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

编辑~/.zshrc

1
2
3
4
5
6
7
8
9
10
11
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
sudo
zsh-syntax-highlighting
zsh-autosuggestions
)

最后记得source .zshrc,然后会进入主题的配置界面,非常简单的交互

最终效果,简约,补全(根据最近历史记录),时间显示,按两次esc可以直接sudo

熟练后在新设备上五分钟不到就OK,如果你发现怎么都没办法把zsh调成默认shell,不妨试一下重启,血压飙升!

参考教程

oh_my_zsh官网

sysin

知乎_theme