Zshis a shell designed for interactive use, although it is also a powerful scripting language. Many of the useful features ofbash,ksh, andtcshwere incorporated into zsh; many original features were added.
Zsh Completion
Share My .zshrc (Refer to Kardinal) here and welcome share your experience.
RPROMPT=' %{[33m%}(%/)'
autoload colors
colors
PROMPT='%{[31m%}%
>>'
exportEDITOR=emacs
#关于历史纪录的配置
# number of lines kept in history
exportHISTSIZE=10000
# # number of lines saved in the history after logout
exportSAVEHIST=10000
# # location of history
exportHISTFILE=~/.zhistory
# # append command to history file once executed
setopt INC_APPEND_HISTORY
#Disable core dumps
limit coredumpsize 0
#Emacs风格键绑定
bindkey -e
#设置DEL键为向后删除
bindkey"\e[3~"delete-char
#以下字符视为单词的一部分
WORDCHARS='*?_-[]~=&;!#$%^(){}<>'
#自动补全功能
setopt AUTO_LIST
setopt AUTO_MENU
setopt MENU_COMPLETE
autoload -U compinit
compinit
# Completion caching
zstyle':completion::complete:*'use-cache on
zstyle':completion::complete:*'cache-path .zcache
#zstyle ':completion:*:cd:*' ignore-parents parent pwd
#Completion Options
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
# Path Expansion
zstyle':completion:*'expand'yes'
zstyle':completion:*'squeeze-shlashes'yes'
zstyle':completion::complete:*''\\'
zstyle':completion:*:*:*:default'menu yesselect
zstyle':completion:*:*:default'force-list always
# GNU Colors 需要/etc/DIR_COLORS文件 否则自动补全时候选菜单中的选项不能彩色显示
[-f /etc/DIR_COLORS]&&eval$(dircolors -b /etc/DIR_COLORS)
exportZLSCOLORS="${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:*'completer _complete _match _approximate
zstyle':completion:*:match:*'original only
zstyle':completion:*:approximate:*'max-errors 1 numeric
compdefpkill=kill
compdefpkill=killall
zstyle':completion:*:*:kill:*'menu yesselect
zstyle':completion:*:processes'command'ps -au$USER'
# Group matches and Describe
zstyle':completion:*:matches'group'yes'
zstyle':completion:*:options'description'yes'
zstyle':completion:*:options'auto-description'%d'
zstyle':completion:*:descriptions'format$'\e[01;33m -- %d --\e[0m'
zstyle':completion:*:messages'format$'\e[01;35m -- %d --\e[0m'
zstyle':completion:*:warnings'format$'\e[01;31m -- No Matches Found --\e[0m'
#命令别名
aliascp='cp -i'
aliasmv='mv -i'
aliasrm='rm -i'
aliasls='ls -F --color=auto'
aliasll='ls -l'
aliasgrep='grep --color=auto'
aliasee='emacsclient -t'
#路径别名 进入相应的路径时只要 cd ~xxx
hash-dWWW="/home/lighttpd/html"
hash-dARCH="/mnt/arch"
hash-dPKG="/var/cache/pacman/pkg"
hash-dE="/etc/env.d"
hash-dC="/etc/conf.d"
hash-dI="/etc/rc.d"
hash-dX="/etc/X11"
hash-dBK="/home/r00t/config_bak"
##for Emacs在Emacs终端中使用Zsh的一些设置 不推荐在Emacs中使用它
if[["$TERM"=="dumb"]];then
setopt No_zle
PROMPT='%[email protected]%M %/
>>'
aliasls='ls -F'
fi
#效果超炫的提示符,如需要禁用,注释下面配置
functionprecmd{
localTERMWIDTH
((TERMWIDTH=${COLUMNS}- 1 ))
###
# Truncate the path if it's too long.
PR_FILLBAR=""
PR_PWDLEN=""
localpromptsize=${#${(%):---(%[email protected]%m:%l)---()--}}
localpwdsize=${#${(%):-%~}}
if[["$promptsize + $pwdsize"-gt$TERMWIDTH]];then
((PR_PWDLEN=$TERMWIDTH-$promptsize))
else
PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize)))..${PR_HBAR}.)}"
fi
###
# Get APM info.
#if which ibam > /dev/null; then
#PR_APM_RESULT=`ibam --percentbattery`
#elif which apm > /dev/null; then
#PR_APM_RESULT=`apm`
#fi
}
setopt extended_glob
preexec (){
if[["$TERM"=="screen"]];then
localCMD=${1[(wr)^(*=*|sudo|-*)]}
echo-n"\ek$CMD\e\\"
fi
}
setprompt (){
###
# Need this so the prompt will work.
setopt prompt_subst
###
# See if we can use colors.
autoload colors zsh/terminfo
if[["$terminfo[colors]"-ge 8]];then
colors
fi
forcolor in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE;do
evalPR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
evalPR_LIGHT_$color='%{$fg[${(L)color}]%}'
((count=$count+ 1 ))
done
PR_NO_COLOUR="%{$terminfo[sgr0]%}"
###
# See if we can use extended characters to look nicer.
typeset-A altchar
set-A altchar${(s..)terminfo[acsc]}
PR_SET_CHARSET="%{$terminfo[enacs]%}"
PR_SHIFT_IN="%{$terminfo[smacs]%}"
PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
PR_HBAR=${altchar[q]:--}
#PR_HBAR=" "
PR_ULCORNER=${altchar[l]:--}
PR_LLCORNER=${altchar[m]:--}
PR_LRCORNER=${altchar[j]:--}
PR_URCORNER=${altchar[k]:--}
###
# Decide if we need to set titlebar text.
case$TERMin
xterm*)
PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%[email protected]%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
;;
screen)
PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%[email protected]%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
;;
*)
PR_TITLEBAR=''
;;
esac
###
# Decide whether to set a screen title
if[["$TERM"=="screen"]];then
PR_STITLE=$'%{\ekzsh\e\\%}'
else
PR_STITLE=''
fi
###
# APM detection
#if which ibam > /dev/null; then
#PR_APM='$PR_RED${${PR_APM_RESULT[(f)1]}[(w)-2]}%%(${${PR_APM_RESULT[(f)3]}[(w)-1]})$PR_LIGHT_BLUE:'
#elif which apm > /dev/null; then
#PR_APM='$PR_RED${PR_APM_RESULT[(w)5,(w)6]/\% /%%}$PR_LIGHT_BLUE:'
#else
PR_APM=''
#fi
###
# Finally, the prompt.
}
setprompt
autoload colors
colors
PROMPT='%{[31m%}%
>>'
exportEDITOR=emacs
#关于历史纪录的配置
# number of lines kept in history
exportHISTSIZE=10000
# # number of lines saved in the history after logout
exportSAVEHIST=10000
# # location of history
exportHISTFILE=~/.zhistory
# # append command to history file once executed
setopt INC_APPEND_HISTORY
#Disable core dumps
limit coredumpsize 0
#Emacs风格键绑定
bindkey -e
#设置DEL键为向后删除
bindkey"\e[3~"delete-char
#以下字符视为单词的一部分
WORDCHARS='*?_-[]~=&;!#$%^(){}<>'
#自动补全功能
setopt AUTO_LIST
setopt AUTO_MENU
setopt MENU_COMPLETE
autoload -U compinit
compinit
# Completion caching
zstyle':completion::complete:*'use-cache on
zstyle':completion::complete:*'cache-path .zcache
#zstyle ':completion:*:cd:*' ignore-parents parent pwd
#Completion Options
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
# Path Expansion
zstyle':completion:*'expand'yes'
zstyle':completion:*'squeeze-shlashes'yes'
zstyle':completion::complete:*''\\'
zstyle':completion:*:*:*:default'menu yesselect
zstyle':completion:*:*:default'force-list always
# GNU Colors 需要/etc/DIR_COLORS文件 否则自动补全时候选菜单中的选项不能彩色显示
[-f /etc/DIR_COLORS]&&eval$(dircolors -b /etc/DIR_COLORS)
exportZLSCOLORS="${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:*'completer _complete _match _approximate
zstyle':completion:*:match:*'original only
zstyle':completion:*:approximate:*'max-errors 1 numeric
compdefpkill=kill
compdefpkill=killall
zstyle':completion:*:*:kill:*'menu yesselect
zstyle':completion:*:processes'command'ps -au$USER'
# Group matches and Describe
zstyle':completion:*:matches'group'yes'
zstyle':completion:*:options'description'yes'
zstyle':completion:*:options'auto-description'%d'
zstyle':completion:*:descriptions'format$'\e[01;33m -- %d --\e[0m'
zstyle':completion:*:messages'format$'\e[01;35m -- %d --\e[0m'
zstyle':completion:*:warnings'format$'\e[01;31m -- No Matches Found --\e[0m'
#命令别名
aliascp='cp -i'
aliasmv='mv -i'
aliasrm='rm -i'
aliasls='ls -F --color=auto'
aliasll='ls -l'
aliasgrep='grep --color=auto'
aliasee='emacsclient -t'
#路径别名 进入相应的路径时只要 cd ~xxx
hash-dWWW="/home/lighttpd/html"
hash-dARCH="/mnt/arch"
hash-dPKG="/var/cache/pacman/pkg"
hash-dE="/etc/env.d"
hash-dC="/etc/conf.d"
hash-dI="/etc/rc.d"
hash-dX="/etc/X11"
hash-dBK="/home/r00t/config_bak"
##for Emacs在Emacs终端中使用Zsh的一些设置 不推荐在Emacs中使用它
if[["$TERM"=="dumb"]];then
setopt No_zle
PROMPT='%[email protected]%M %/
>>'
aliasls='ls -F'
fi
#效果超炫的提示符,如需要禁用,注释下面配置
functionprecmd{
localTERMWIDTH
((TERMWIDTH=${COLUMNS}- 1 ))
###
# Truncate the path if it's too long.
PR_FILLBAR=""
PR_PWDLEN=""
localpromptsize=${#${(%):---(%[email protected]%m:%l)---()--}}
localpwdsize=${#${(%):-%~}}
if[["$promptsize + $pwdsize"-gt$TERMWIDTH]];then
((PR_PWDLEN=$TERMWIDTH-$promptsize))
else
PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize)))..${PR_HBAR}.)}"
fi
###
# Get APM info.
#if which ibam > /dev/null; then
#PR_APM_RESULT=`ibam --percentbattery`
#elif which apm > /dev/null; then
#PR_APM_RESULT=`apm`
#fi
}
setopt extended_glob
preexec (){
if[["$TERM"=="screen"]];then
localCMD=${1[(wr)^(*=*|sudo|-*)]}
echo-n"\ek$CMD\e\\"
fi
}
setprompt (){
###
# Need this so the prompt will work.
setopt prompt_subst
###
# See if we can use colors.
autoload colors zsh/terminfo
if[["$terminfo[colors]"-ge 8]];then
colors
fi
forcolor in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE;do
evalPR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
evalPR_LIGHT_$color='%{$fg[${(L)color}]%}'
((count=$count+ 1 ))
done
PR_NO_COLOUR="%{$terminfo[sgr0]%}"
###
# See if we can use extended characters to look nicer.
typeset-A altchar
set-A altchar${(s..)terminfo[acsc]}
PR_SET_CHARSET="%{$terminfo[enacs]%}"
PR_SHIFT_IN="%{$terminfo[smacs]%}"
PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
PR_HBAR=${altchar[q]:--}
#PR_HBAR=" "
PR_ULCORNER=${altchar[l]:--}
PR_LLCORNER=${altchar[m]:--}
PR_LRCORNER=${altchar[j]:--}
PR_URCORNER=${altchar[k]:--}
###
# Decide if we need to set titlebar text.
case$TERMin
xterm*)
PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%[email protected]%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
;;
screen)
PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%[email protected]%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
;;
*)
PR_TITLEBAR=''
;;
esac
###
# Decide whether to set a screen title
if[["$TERM"=="screen"]];then
PR_STITLE=$'%{\ekzsh\e\\%}'
else
PR_STITLE=''
fi
###
# APM detection
#if which ibam > /dev/null; then
#PR_APM='$PR_RED${${PR_APM_RESULT[(f)1]}[(w)-2]}%%(${${PR_APM_RESULT[(f)3]}[(w)-1]})$PR_LIGHT_BLUE:'
#elif which apm > /dev/null; then
#PR_APM='$PR_RED${PR_APM_RESULT[(w)5,(w)6]/\% /%%}$PR_LIGHT_BLUE:'
#else
PR_APM=''
#fi
###
# Finally, the prompt.
}
setprompt