Zsh 配置
本文最后更新于:2024年3月18日 凌晨
Zsh 配置
别名设置
zsh
不仅可以设置通用别名,还能针对文件类型设置对应的打开程序,比如。
alias -s html=vi
,意思就是你在命令行输入 hello.html
,zsh
会为你自动打开vim
并读取hello.html
alias -s gz='tar -xzvf'
,表示自动解压后缀为gz
的压缩包。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 alias cls='clear' alias ll='ls -l' alias la='ls -a' alias vi='vim' alias javac="javac -J-Dfile.encoding=utf8" alias grep="grep --color=auto" alias -s html=vi alias -s rb=vi alias -s py=vi alias -s js=vialias -s c=vialias -s java=vialias -s txt=vialias -s gz='tar -xzvf' alias -s tgz='tar -xzvf' alias -s zip='unzip' alias -s bz2='tar -xjvf'
主题设置
oh my zsh 提供了数十种主题,相关文件在~/.oh-my-zsh/themes
目录下。
ZSH_THEME="random"
主题设置为随机,这样我们每打开一个窗口,都会随机在默认主题中选择一个。
安装powerlevel10k主题。
1 2 3 git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME /.oh-my-zsh/custom} /themes/powerlevel10k brew install powerlevel10k
1 ZSH_THEME="powerlevel10k/powerlevel10k"
1 https:// aur.archlinux.org/packages/ ttf-meslo-nerd-font-powerlevel10k/
插件设置
oh my zsh
项目提供了完善的插件体系,相关的文件在~/.oh-my-zsh/plugins
目录下,默认提供了100多种。
想了解每个插件的功能,只要打开相关目录下的 zsh
文件。
插件也是在~/.zshrc
里配置,找到plugins
关键字,就可以加载自己的插件了,系统默认加载git
,你可以在后面追加内容,如下:
1 2 3 4 5 6 7 8 9 10 11 12 plugins=(git docker docker-compose mvn node npm yarn sudo zsh-syntax-highlighting zsh-autosuggestions zsh-completions autojump)
1 git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} /plugins/zsh-autosuggestions
安装 zsh-syntax-highlighting
1 git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} /plugins/zsh-syntax-highlighting
1 https://github.com/wting/autojump
1 git clone https://gi thub.com/zsh-users/ zsh-completions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} /plugins/ zsh-completions
vicmd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 # vicmd bindkey -v bindkey -M vicmd "i" vi-insert bindkey -M vicmd "I" vi-insert-bol bindkey -M vicmd "h" vi-backward-char bindkey -M vicmd "l" vi-forward-char bindkey -M vicmd "H" vi-beginning-of-line bindkey -M vicmd "L" vi-end-of-line bindkey -M vicmd "j" down-line-or-history bindkey -M vicmd "k" up-line-or-history bindkey -M vicmd "u" undo# bindkey -M vicmd "-" vi-rev-repeat-search bindkey -M vicmd "=" vi-repeat-search function zle-keymap-select { if [[ ${KEYMAP} == vicmd ]] || [[ $1 = 'block' ]]; then echo -ne '\e[1 q' elif [[ ${KEYMAP} == main ]] || [[ ${KEYMAP} == viins ]] || [[ ${KEYMAP} = '' ]] || [[ $1 = 'beam' ]]; then echo -ne '\e[5 q' fi } zle -N zle-keymap-select
代理配置
手动配置
1 export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890
自动配置
1 2 3 4 5 6 7 8 9 10 # 开启代理 function proxy_on(){ export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890 echo -e "proxy on"; }# 关闭代理 function proxy_off(){ unset https_proxy http_proxy all_proxy; echo -e "proxy off"; }
检查代理
1 2 3 curl ip.gs curl ipinfo.io wget https://www.dropbox.com -v -O /dev/null