zsh的使用

186 阅读1分钟

安装

rockylinux9先安装:

sudo dnf install util-linux-user -y
dnf  install epel-release 

文档地址:zhuanlan.zhihu.com/p/50464006
haoyep.com/posts/zsh-c…

  1. There are two main ways to install Zsh:

  2. Verify installation by running zsh --version. Expected result: zsh 5.0.8 or more recent.

  3. Make it your default shell: chsh -s $(which zsh) or use sudo lchsh $USER(rocky上) if you are on Fedora.

    • Note that this will not work if Zsh is not in your authorized shells list (/etc/shells) or if you don't have permission to use chsh. If that's the case you'll need to use a different procedure.
    • If you use lchsh you need to type /bin/zsh to make it your default shell.
  4. Log out and log back in again to use your new default shell.

  5. Test that it worked with echo $SHELL. Expected result: /bin/zsh or similar.

  6. Test with $SHELL --version. Expected result: 'zsh 5.8' or similar

安装# Oh my zsh.

gist.github.com/dogrocker/1…

Install with curl

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

Enabling Plugins (zsh-autosuggestions & zsh-syntax-highlighting)

  • Download zsh-autosuggestions by

git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions

  • Download zsh-syntax-highlighting by

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

  • nano ~/.zshrc find plugins=(git)
  • Append zsh-autosuggestions & zsh-syntax-highlighting to plugins() like this

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


强烈建议主题:

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

# 中国用户可以使用 gitee.com 上的官方镜像加速下载
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

在 ~/.zshrc 设置 ZSH_THEME="powerlevel10k/powerlevel10k"。接下来,终端会自动引导你配置 powerlevel10k。 1

sudo wget -O $ZSH_CUSTOM/themes/haoomz.zsh-theme https://cdn.haoyep.com/gh/leegical/Blog_img/zsh/haoomz.zsh-theme

编辑 ~/.zshrc 文件,将 ZSH_THEME 设为 haoomz。当然你也可以设置为其他主题,例如lukerandallrobbyrussell

  • Reopen terminal

安装autojump

$ sudo apt install autojump      [On Debian, Ubuntu and Mint]
$ sudo yum install autojump       [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
$ sudo emerge -a autojump        [On Gentoo Linux]
$ sudo apk add autojump          [On Alpine Linux]
$ sudo pacman -S autojump        [On Arch Linux]
$ sudo zypper install autojump   [On OpenSUSE]   

ZSH_THEME="agnoster"
plugins=(
        kubectl 
        dnf
        git  
        autojump
        zsh-autosuggestions
        zsh-syntax-highlighting
)

source ~/.zshrc

root账号下安装:

需要使用sudo命令

sudo cp -r /home/cyxinda/.oh-my-zsh    /root
sudo cp -r /home/cyxinda/.zshrc    /root

安装好zsh后,需要一些,能够使ctr+w的行为与bash一致:

# Create a new widget.
zle -N backward-kill-space-word
backward-kill-space-word() {
  # Inform the line editor that this widget will kill text.
  zle -f kill

  # Set $WORDCHARS for this command only.
  WORDCHARS='*?_-.[]~=/&;!#$%^(){}<>' zle .backward-kill-word
}

# See comments above.
zle -N backward-kill-bash-word
backward-kill-bash-word() {
  zle -f kill
  WORDCHARS='' zle .backward-kill-word
}

# Bind the widgets to keys.
bindkey '^W' backward-kill-space-word
bindkey '^[^H' backward-kill-bash-word