ZSH
ZSH
一、安装
1.1 Ubuntu 安装
$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
1.2 CentOS 无Root权限安装
1.2.1 编译zsh
从 sourceforge 下载最新的zsh源码并解压
mkdir zsh && tar -xvf zsh.tar.xz -C zsh --strip-components 1
安装
# 配置,我这边将zsh安装到~/usr下
cd zsh
./configure --prefix=$HOME/usr/
make
make install
安装完毕以后可以执行一下看看是否成功
~/usr/bin/zsh
1.2.2 安装oh-my-zsh
首先配置bash登录跳转zsh,编辑.bash_profile
添加一下内容,注意路径!
export PATH=$HOME/usr/bin:$PATH
export SHELL=`which zsh`
[ -f "$SHELL" ] && exec "$SHELL" -l
安装 oh-my-zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
1.3 安装插件
1.3.1 自动补全 -- zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# 编辑 ~/.zshrc 添加插件
plugins=(zsh-autosuggestions)
如果你在CentOS下面使用,默认提示可能不是灰色的,这里可以在.zshrc
文件添加配置(注意放到插件加载之后)
# fg后面的数字可以更改以显示不同的颜色
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=2'
1.3.2 查找当前目录下的文件 FZF
brew install fzf
/opt/homebrew/opt/fzf/install
安装以后按Ctrl+T
可以呼出查找界面.
1.3.3 快速跳转目录 -- z
无需安装,直接添加插件即可。
# 编辑 ~/.zshrc 添加插件
plugins=(z)
例子:
z foo cd to most frecent dir matching foo
z foo bar cd to most frecent dir matching foo, then bar
z -r foo cd to highest ranked dir matching foo
z -t foo cd to most recently accessed dir matching foo
z -l foo list all dirs matching foo (by frecency)
1.3.4 zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
source ./zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
二、配置
终端显示前缀
开启多个终端的时候经常分不清楚SSH的机器,可以通过配置~/.zshrc
增加终端的前缀。
PROMPT="VPS-"$PROMPT
我的 alias 清单
## Show hidden files ##
alias l.='ls -d .* --color=auto'
## get rid of command not found ##
alias cd..='cd ..'
## a quick way to get out of current directory ##
alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../'
alias .4='cd ../../../../'
alias .5='cd ../../../../..'
## Colorize the grep command output for ease of use (good for log files)##
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
## Create parent directories on demand
alias mkdir='mkdir -pv'
alias path='echo -e ${PATH//:/\\n}'
alias now='date +"%T"'
alias nowtime=now
alias nowdate='date +"%Y-%m-%d"'
## top
alias cpu='top -o cpu'
alias mem='top -o rsize' # memory
## copy the working directory path
alias cpwd='pwd|tr -d "\n"|pbcopy'
## DNS
alias flush="sudo killall -HUP mDNSResponder"
## Get your current public IP
alias ip="curl icanhazip.com"
alias untar='tar -zxvf '
alias wget='wget -c '
alias getpass="openssl rand -base64 20"
alias ipe='curl ipinfo.io/ip'
alias ipi='ipconfig getifaddr en0'
alias cat='bat'
PROMPT="MAC-"$PROMPT
ssh 执行提示找不到命令问题
zsh非登录的时候访问的是.zshenv
,所以需要将变量放在这里