ubuntu20.04安装zsh,并添加相关工具

1.查看当前可用shell

cat /etc/shells

2.查看当前默认shell

echo $SHELL

3.下载安装zsh

sudo apt install zsh

4.下载安装oh my zsh

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

5.添加语法高亮、自动补齐等插件

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh}/plugins/zsh-autosuggestions
sudo apt-get install autojump

6.设置zsh自动启动

chsh -s /bin/zsh root
chsh -s /bin/zsh

在.bashrc中添加:

if [ -t 1 ]; then
    exec zsh
fi

7.修改配置文件

sudo gedit ~/.zshrc

zsh安装路径

export ZSH="$HOME/.oh-my-zsh"

设置主题

ZSH_THEME="ys"

导入安装的插件

plugins=(git)
plugins=(git history-substring-search autojump zsh-autosuggestions zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh

个性化文字

precmd(){
    echo -e "                          ~~哟呵,又在写bug o_o#"
}

多个终端不要直接共享历史命令

setopt EXTENDED_HISTORY
setopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt nosharehistory
setopt INC_APPEND_HISTORY
setopt incappendhistorytime
export HISTFILESIZE=1000000000
export HISTSIZE=1000000000
export HISTTIMEFORMAT="[%F %T] "
export HISTFILE=~/.zsh_history

解决使用zsh后小键盘区无效问题

# key bindings
bindkey "\e[1~" beginning-of-line
bindkey "\e[4~" end-of-line
bindkey "\e[5~" beginning-of-history
bindkey "\e[6~" end-of-history

# for rxvt
bindkey "\e[8~" end-of-line
bindkey "\e[7~" beginning-of-line
# for non RH/Debian xterm, can't hurt for RH/DEbian xterm
bindkey "\eOH" beginning-of-line
bindkey "\eOF" end-of-line
# for freebsd console
bindkey "\e[H" beginning-of-line
bindkey "\e[F" end-of-line
# completion in the middle of a line
bindkey '^i' expand-or-complete-prefix

# Fix numeric keypad  
# 0 . Enter  
bindkey -s "^[Op" "0"
bindkey -s "^[On" "."
bindkey -s "^[OM" "^M"
# 1 2 3  
bindkey -s "^[Oq" "1"
bindkey -s "^[Or" "2"
bindkey -s "^[Os" "3"
# 4 5 6  
bindkey -s "^[Ot" "4"
bindkey -s "^[Ou" "5"
bindkey -s "^[Ov" "6"
# 7 8 9  
bindkey -s "^[Ow" "7"
bindkey -s "^[Ox" "8"
bindkey -s "^[Oy" "9"
# + - * /  
bindkey -s "^[Ol" "+"
bindkey -s "^[Om" "-"
bindkey -s "^[Oj" "*"
bindkey -s "^[Oo" "/"

猜你喜欢

转载自blog.csdn.net/weixin_45112559/article/details/130912871