如果您想了解zsh+on-my-zsh配置教程指南和程序员必备的知识,那么本篇文章将是您的不二之选。我们将深入剖析zsh+on-my-zsh配置教程指南的各个方面,并为您解答程序员必备的疑在这篇文章中
如果您想了解zsh+on-my-zsh配置教程指南和程序员必备的知识,那么本篇文章将是您的不二之选。我们将深入剖析zsh+on-my-zsh配置教程指南的各个方面,并为您解答程序员必备的疑在这篇文章中,我们将为您介绍zsh+on-my-zsh配置教程指南的相关知识,同时也会详细的解释程序员必备的运用方法,并给出实际的案例分析,希望能帮助到您!
本文目录一览:- zsh+on-my-zsh配置教程指南(程序员必备)(zsh 配置)
- .zsh配置
- 2022 我的zsh配置
- CentOS7安装zsh和oh-my-zsh
- From bash to zsh - [ oh-my-zsh + powerlevel9k ]
zsh+on-my-zsh配置教程指南(程序员必备)(zsh 配置)
本文以CentOS 7/Mac 为例,介绍zsh的配置使用教程。
准备
查看当前环境shell
echo $SHELL
查看系统自带哪些shell
cat /etc/shells
安装zsh
yum install zsh # CentOS brew install zsh # mac安装
将zsh
设置为默认shell
chsh -s /bin/zsh # CentOS
# Mac如下 # 在 /etc/shells 文件中加入如下一行 /usr/local/bin/zsh # 接着运行 chsh -s /usr/local/bin/zsh
可以通过echo $SHELL
查看当前默认的shell,如果没有改为/bin/zsh
,那么需要重启shell。
oh-my-zsh
配置zsh是一件麻烦的事儿,爱折腾的程序猿怎么可能忍受?!于是,oh-my-zsh出现了,有了这个东东,zsh配置起来就方便多了!
安装oh-my-zsh
有若干安装方式,介绍三种:
1.自动安装
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
2.手动安装
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
3.真-手动安装
- 在oh-my-zsh的github主页,手动将zip包下载下来。
- 将zip包解压,拷贝至
~/.oh-my-zsh
目录。此处省略拷贝的操作步骤。 - 执行
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
三选一即可,适合各种环境下的安装,然后需要source ~./.zshrc
将配置生效。以下修改了.zshrc
文件之后,都执行一下这个命令。
zsh主题
通过如下命令可以查看可用的Theme
:
# ls ~/.oh-my-zsh/themes
如何修改zsh主题呢?
编辑~/.zshrc
文件,将ZSH_THEME="candy"
,即将主题修改为candy
。我采用的steeef
。
zsh扩展
在~/.zshrc
中找到plugins
关键字,就可以自定义启用的插件了,系统默认加载git
。
git插件
命令内容可以参考cat ~/.oh-my-zsh/plugins/git/git.plugin.zsh
。
常用的:
gapa git add --patch gc! git commit -v --amend gcl git clone --recursive gclean git reset --hard && git clean -dfx gcm git checkout master gcmsg git commit -m gco git checkout gd git diff gdca git diff --cached gp git push grbc git rebase --continue gst git status gup git pull --rebase
完整列表:https://github.com/robbyrussell/oh-my-zsh/wiki/Plugin:git
extract
解压文件用的,所有的压缩文件,都可以直接x filename
,不用记忆参数
当然,如果你想要用tar
命令,可以使用tar -
加tab
键,zsh会列出参数的含义。
autojump
按照官方文档介绍,需要使用如下命令安装,而不是一些博客中的介绍:
yum install autojump-zsh # CentOS brew install autojump # Mac
CentOS
安装好之后,需要在~/.zshrc
中配置一下,除了在plugins
中增加autojump
之外,还需要添加一行:
[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh
安装好之后,记得source ~/.zshrc
,然后你就可以通过j+目录名
快速进行目录跳转。支持目录名的模糊匹配和自动补全。
-
j -stat
:可以查看历史路径库
zsh-autosuggestions
zsh-autosuggestions
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
在 ~/.zshrc
中配置
plugins=(其他的插件 zsh-autosuggestions)
因为箭头→
不太方便,在.zshrc
中自定义补全快捷键为逗号,但是又一次遇到了需要输入逗号的情况,所以,并不太推荐如下修改:
bindkey ',' autosuggest-accept
zsh-Syntax-highlighting
zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-Syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-Syntax-highlighting
~/.zshrc
文件中配置:
plugins=(其他的插件 zsh-Syntax-highlighting)
git-open
git-open插件可以在你git项目下打开远程仓库浏览项目。
git clone https://github.com/paulirish/git-open.git $ZSH_CUSTOM/plugins/git-open
bat
bat
代替 cat
cat
某个文件,可以在终端直接输出文件内容,bat
相比 cat
增加了行号和颜色高亮 ??
brew install bat
常用快捷键
- 命令历史记录
- 一旦在 shell 敲入正确命令并能执行后,shell 就会存储你所敲入命令的历史记录(存放在
~/.zsh_history
文件中),方便再次运行之前的命令。可以按方向键↑和↓来查看之前执行过的命令 - 可以用
r
来执行上一条命令 - 使用
ctrl-r
来搜索命令历史记录
- 一旦在 shell 敲入正确命令并能执行后,shell 就会存储你所敲入命令的历史记录(存放在
- 命令别名
- 可以简化命令输入,在
.zshrc
中添加alias shortcut=‘this is the origin command‘
一行就相当于添加了别名 - 在命令行中输入
alias
可以查看所有的命令别名
- 可以简化命令输入,在
使用技巧
- 连按两次Tab会列出所有的补全列表并直接开始选择,补全项可以使用 ctrl+n/p/f/b上下左右切换
- 智能跳转,安装了 autojump 之后,zsh 会自动记录你访问过的目录,通过 j 目录名 可以直接进行目录跳转,而且目录名支持模糊匹配和自动补全,例如你访问过 hadoop-1.0.0 目录,输入j hado 即可正确跳转。j --stat 可以看你的历史路径库。
- 命令选项补全。在zsh中只需要键入 tar -
就会列出所有的选项和帮助说明 - 在当前目录下输入 .. 或 ... ,或直接输入当前目录名都可以跳转,你甚至不再需要输入
cd
命令了。在你知道路径的情况下,比如/usr/local/bin
你可以输入cd /u/l/b
然后按进行补全快速输入 - 目录浏览和跳转:输入 d,即可列出你在这个会话里访问的目录列表,输入列表前的序号,即可直接跳转。
- 命令参数补全。键入
kill <tab>
就会列出所有的进程名和对应的进程号 - 更智能的历史命令。在用或者方向上键查找历史命令时,zsh支持限制查找。比如,输入ls,然后再按方向上键,则只会查找用过的ls命令。而此时使用则会仍然按之前的方式查找,忽略 ls
- 多个终端会话共享历史记录
- 通配符搜索:
ls -l **/*.sh
,可以递归显示当前目录下的 shell 文件,文件少时可以代替find
。使用**/
来递归搜索 - 扩展环境变量,输入环境变量然后按 就可以转换成表达的值
- 在 .zshrc 中添加
setopt HIST_IGnorE_DUPS
可以消除重复记录,也可以利用sort -t ";" -k 2 -u ~/.zsh_history | sort -o ~/.zsh_history
手动清除
参考
- wting/autojump--官方文档
- powerline/fonts
Linux
- 终极 Shell
- Ubuntu 16.04下安装zsh和oh-my-zsh
- Ubuntu 下安装oh-my-zsh
- 掘金-Shell 中的极品-- Zsh
- CentOS 7下autojump无法使用的可能原因
- oh-my-zsh配置你的zsh提高shell逼格终极选择
Mac
- zsh oh-my-zsh 插件推荐
- zsh 全程指南-推荐
- iterm主题下载
- 程序员内功系列--iTerm与Zsh篇
- Mac 下配置终端环境 iTerm2 + Zsh + Oh My Zsh + tmux
最后
- Github-Michael728/my-config-files 附上我的配置文件地址;
- zsh+on-my-zsh配置教程指南 本文地址
.zsh配置
# Path to your oh-my-zsh installation.
export ZSH=/home/zcy/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it''ll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="re5et"
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
#color{{{
autoload -U colors
colors
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
eval _$color=''%{$terminfo[bold]$fg[${(L)color}]%}''
eval $color=''%{$fg[${(L)color}]%}''
(( count = $count + 1 ))
done
FINISH="%{$terminfo[sgr0]%}"
#}}}
#命令提示符
RPROMPT=$(echo "$RED%D %T$FINISH")
PROMPT=$(echo "$CYAN%n@$YELLOW%M:$GREEN%/$_YELLOW>$FINISH ")
export EDITOR=vim
#为历史纪录中的命令添加时间戳
setopt EXTENDED_HISTORY
#启用 cd 命令的历史纪录,cd -[TAB]进入历史路径
setopt AUTO_PUSHD
#相同的历史路径只保留一个
setopt PUSHD_IGNORE_DUPS
#自动补全功能 {{{
setopt AUTO_LIST
setopt AUTO_MENU
#开启此选项,补全时会直接选中菜单项
#setopt MENU_COMPLETE
autoload -U compinit
compinit
#自动补全缓存
#zstyle '':completion::complete:*'' use-cache on
#zstyle '':completion::complete:*'' cache-path .zcache
#zstyle '':completion:*:cd:*'' ignore-parents parent pwd
#自动补全选项
zstyle '':completion:*'' verbose yes
zstyle '':completion:*'' menu select
zstyle '':completion:*:*:default'' force-list always
zstyle '':completion:*'' select-prompt ''%SSelect: lines: %L matches: %M [%p]''
zstyle '':completion:*:match:*'' original only
zstyle '':completion::prefix-1:*'' completer _complete
zstyle '':completion:predict:*'' completer _complete
zstyle '':completion:incremental:*'' completer _complete _correct
zstyle '':completion:*'' completer _complete _prefix _correct _prefix _match _approximate
#路径补全
zstyle '':completion:*'' expand ''yes''
zstyle '':completion:*'' squeeze-shlashes ''yes''
zstyle '':completion::complete:*'' ''\\''
#彩色补全菜单
eval $(dircolors -b)
export ZLSCOLORS="${LS_COLORS}"
zmodload zsh/complist
zstyle '':completion:*'' list-colors ${(s.:.)LS_COLORS}
zstyle '':completion:*:*:kill:*:processes'' list-colors ''=(#b) #([0-9]#)*=0=01;31''
#修正大小写
zstyle '':completion:*'' matcher-list '''' ''m:{a-zA-Z}={A-Za-z}''
#错误校正
zstyle '':completion:*'' completer _complete _match _approximate
zstyle '':completion:*:match:*'' original only
zstyle '':completion:*:approximate:*'' max-errors 1 numeric
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
setopt extended_glob
TOKENS_FOLLOWED_BY_COMMANDS=(''|'' ''||'' '';'' ''&'' ''&&'' ''sudo'' ''do'' ''time'' ''strace'')
recolor-cmd() {
region_highlight=()
colorize=true
start_pos=0
for arg in ${(z)BUFFER}; do
((start_pos+=${#BUFFER[$start_pos+1,-1]}-${#${BUFFER[$start_pos+1,-1]## #}}))
((end_pos=$start_pos+${#arg}))
if $colorize; then
colorize=false
res=$(LC_ALL=C builtin type $arg 2>/dev/null)
case $res in
*''reserved word''*) ;;
*''alias for''*) ;;
*''shell builtin''*) ;;
*''shell function''*) fg=green,bold'';;
*"$arg is"*)
[[ $arg = ''sudo'' ]] &&||;;
*) none,bold'';;
esac
region_highlight+=("$start_pos $end_pos $style")
fi
[[ ${${TOKENS_FOLLOWED_BY_COMMANDS[(r)${arg//|/\|}]}:+yes} = ''yes'' ]] && colorize=true
start_pos=$end_pos
done
}
check-cmd-self-insert() { zle .self-insert && recolor-cmd }
check-cmd-backward-delete-char() { zle .backward-delete-char && recolor-cmd }
zle -N self-insert check-cmd-self-insert
zle -N backward-delete-char check-cmd-backward-delete-char
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
#在pugin之前要先source incr,否则incr不能生效,如果把source放到plugin之后,则无法支持zsh tab键选择目录
source ~/.oh-my-zsh/custom/plugins/incr/incr-0.2.zsh
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
#其中incr,放在.oh-my-zsh/plugins/,或.oh-my-zsh/custom/plugins/中
plugins=(git zsh-syntax-highlighting incr)
# User configuration
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:usr/local/java/jdk1.8.0_65/bin:/usr/local/apache-maven-3.3.9/bin"
# export MANPATH="/usr/local/man:$MANPATH"
export LD_LIBRARY_PATH="/usr/local/lib"
export MAVEN_HOME="/usr/local/apache-maven-3.3.9/bin"
export PROTOBUF_HOME="/usr/bin/protoc"
export FLATBUFFER_HOME="/usr/local/bin/flatc"
source $ZSH/oh-my-zsh.sh
zstyle '':completion::approximate:'' max-errors 1 numeric
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR=''vim''
# else
# export EDITOR=''mvim''
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# ssh
# export SSH_KEY_PATH="~/.ssh/dsa_id"
# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
alias ..=''cd ..''
alias vi=''vim''
alias vm0=''ssh root@10.0.0.10''
alias vm1=''ssh root@10.0.0.11''
alias vm2=''ssh root@10.0.0.12''
alias vm3=''ssh root@10.0.0.13''
alias vm4=''ssh root@10.0.0.14''
alias vm5=''ssh root@10.0.0.15''
alias vm6=''ssh root@10.0.0.16''
2022 我的zsh配置
截图
安装zsh, neovim, antigen,pyenv,nvm
sudo apt install zsh
curl -L git.io/antigen > ~/.antigen.zsh
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
curl https://pyenv.run | bash
sudo apt install neovim
sudo apt install pipenv
sudo apt install git
sudo apt install legit
legit --install
chsh -s $(which zsh)
编辑 ~/.zshrc
source ~/.antigen.zsh
antigen use oh-my-zsh
antigen bundle git
antigen bundle heroku
antigen bundle pip
antigen bundle lein
antigen bundle nvm
antigen bundle pyenv
antigen bundle last-working-dir
antigen bundle autojump
antigen bundle zsh-users/zsh-autosuggestions
antigen bundle command-not-found
antigen bundle zsh-users/zsh-completions
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle mafredri/zsh-async
antigen bundle sindresorhus/pure
antigen apply
alias vim=nvim
执行
source ~/.zshrc
CentOS7安装zsh和oh-my-zsh
CentOS7安装zsh和oh-my-zsh 转载地址
From bash to zsh - [ oh-my-zsh + powerlevel9k ]
隨著Mac Catalina的更新,iTerm2跳出了''chsh -s /bin/zsh''
的提示,不想mute提示,就跟著下了指令。
結果...空蕩蕩的自訂的函數跟welcome msg都不見了...
原本系統bash底下的介面為
決定花些時間調整了一下shell環境來配合zsh
安裝教學我就不提了,主要就是分享踩過的坑跟幾個配置
.zshrc裡面這段可能會出現powerline-config找不到
source /Users/ives/Library/Python/2.7/lib/python/site-packages/powerline/bindings/zsh/powerline.zsh
有兩個解法
a.PATH加上"/Users/{user_name}/Library/Python/2.7/bin"
b.拷貝/Users/{user_name}/Library/Python/2.7/bin/powerline-config到資料夾
Powerlevel9k github的font安裝教學,我從option 1裝到了4,最後用POWERLEVEL9K_MODE=''nerdfont-complete''
這過程可謂是曲折...裝好字體後,進行設定
zsh-syntax-highlighting & autojump這兩個套件挺好用,接觸不多只能推薦一下這兩個。一個是語法高亮,一個是權重你訪問的路徑快速跳轉
j github.com ---> 最接近
j ---> 權重最高(?
對我來說覺得真香
Prompt & custom icon & 顏色
首先Prompt切開成左跟右,啟用哪些Segments,你自己加,可以上官網查現成的
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=( os_icon custom_go custom_python context dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=( status time dir_writable )
再來是custom icon,我舉custom_go這個segment為例子,go的小土撥鼠圖標為e724,可以上nerd font去查詢。再來是色碼,印象中官網也有對照的色表,我相信各位應該能觀察怎麼調segment顏色
POWERLEVEL9K_CUSTOM_GO="echo -n go''\ue724''"
POWERLEVEL9K_CUSTOM_GO_FOREGROUND="black"
POWERLEVEL9K_CUSTOM_GO_BACKGROUND="051"
最後附上我的POWERLEVEL9k設定以及效果圖
當然,也可以自訂一些函數在custom_go裡面
至於vim的話,挺習慣自己vimrc,等哪天有空再來折騰vim powerline.....
bash底下的自訂函數迭代方式更直覺以及if裡==要換成=來判斷
例如:
if [ "$1" == "1" ];then ==> if [ "$1" = "1" ];then
以及
for i in ${!mydir[@]} ==> for i in $mydir
目前想到就這些,祝大家Happy hacking!!
補上幾個網址:
https://github.com/Powerlevel...
https://github.com/Powerlevel...
http://zsh.sourceforge.net/Do...
今天关于zsh+on-my-zsh配置教程指南和程序员必备的介绍到此结束,谢谢您的阅读,有关.zsh配置、2022 我的zsh配置、CentOS7安装zsh和oh-my-zsh、From bash to zsh - [ oh-my-zsh + powerlevel9k ]等更多相关知识的信息可以在本站进行查询。
本文标签: