archlinux: zsh安装与配置

zsh安装与配置

前言:

为了方便配置与使用zsh,并且减少更换电脑的时候配置linux环境所花费的时间,在这里记录zsh的安装与配置所使用的指令。注意:本教程在archlinux环境下进行。

安装:

在linux当中使用相对应的包管理软件进行安装,下面展示 archlinux 的安装与相对应的zsh插件配置:

sudo pacman -S zsh

配置:

配置包括常用插件,zsh 设置
  • 常用插件:
    • community/zsh-syntax-highlighting
      • 语法高亮
    • community/zsh-lovers
    • community/zsh-history-substring-search
    • community/zsh-completions
    • community/zsh-autosuggestions

为了可以正常使用,切换bash到zsh:

chsh -s /usr/bin/zsh
安装上面的插件:
sudo pacman -S zsh-syntax-highlighting zsh-lovers zsh-completions zsh-autosuggestions fzf

为了方便设置,顺便使用一个oh-my-zsh的框架,这里使用yay 进行 aur 仓库管理,倘若没有,需要添加archlinuxcn软件源,安装一个 AUR 库管理工具:

  1. 编辑 /etc/pacman.d
  2. 添加下面内容到文件底部:
[archlinuxcn]
SigLevel = Optional TrustAll
Server = http://repo.archlinuxcn.org/$arch
  1. 保存,更新软件包信息:
sudo pacman -Sy
  1. 然后安装 yay 包
sudo pacman -S yay
  1. 安装oh-my-zsh
yay oh-my-zsh

下面是正常使用的配置文件,当中的内容分别从 oh-my-zsh当中的zshrc 提取和我自己编写,我自己编写内容参考了部分网络内容(比如archlinux wiki当中关于zsh 的介绍.)

# zsh config
HISTFILE=~/.cache/zsh_history
HISTSIZE=5000
SAVEHIST=10000
# Path to your oh-my-zsh installation.
ZSH=/usr/share/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="dst"
# 我比较喜欢使用这个zsh主题,其中的命令位置对齐,方便查找。
# 下面是oh-my-zsh的插件,具体使用那些见 /usr/share/oh-my-zsh/scripts 当中的内容。
plugins=(
	 git
	 adb
	 fd
	 screen
	 man
	 fzf
	 sudo 
	 systemd
	 cp 
	 python
	 pyenv
	)


ZSH_CACHE_DIR=$HOME/.cache/oh-my-zsh
if [[ ! -d $ZSH_CACHE_DIR ]]; then
  mkdir $ZSH_CACHE_DIR
fi

source $ZSH/oh-my-zsh.sh

setopt printexitvalue
setopt CORRECT
setopt CORRECT_ALL


autoload -U colors
# colors
# Simple Prompt username@hostname dir %
setopt prompt_subst
# PROMPT='%F{blue}%n%f@%m %2~ %# '

# use autocde
setopt  autocd

# Use Vim keybindings
bindkey -v

# Completion
zstyle ':completion:*' menu select 
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
autoload -Uz compinit
compinit


# alias
alias grep='grep --colour=auto'
alias egrep='egrep --colour=auto'
alias fgrep='fgrep --colour=auto'
alias ls='ls --color=auto --human-readable --group-directories-first --classify'
alias ll='ls --color=auto --human-readable --group-directories-first --classify -l'
alias la='ls --color=auto --human-readable --group-directories-first --classify -la'
alias vim=nvim
alias vi=nvim
alias parui="paru -Slq | fzf --multi --preview 'paru -Si {1}' | xargs -ro paru -S"
alias parur="paru -Qq | fzf --multi --preview 'paru -Qi {1}' | xargs -ro paru -Rns"
if [[ "$TERM" == "xterm-kitty" ]] then
  alias ssh="kitty +kitten ssh"
fi

# functions
man() {
  env \
    LESS_TERMCAP_mb=$(printf "\e[1;31m") \
    LESS_TERMCAP_md=$(printf "\e[1;31m") \
    LESS_TERMCAP_me=$(printf "\e[0m") \
    LESS_TERMCAP_se=$(printf "\e[0m") \
    LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
    LESS_TERMCAP_ue=$(printf "\e[0m") \
    LESS_TERMCAP_us=$(printf "\e[1;32m") \
    man "$@"
}

# source some plugins
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/share/fzf/key-bindings.zsh 
source /usr/share/fzf/completion.zsh
source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh

安装完整展示图:

展示图

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值