# ZSH

# 安装

# Ubuntu 安装

$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
1

# CentOS 无Root权限安装

# 编译zsh

sourceforge (opens new window) 下载最新的zsh源码并解压

mkdir zsh && tar -xvf zsh.tar.xz -C zsh --strip-components 1
1

安装

# 配置,我这边将zsh安装到~/usr下
cd zsh
./configure --prefix=$HOME/usr/
make
make install
1
2
3
4
5

安装完毕以后可以执行一下看看是否成功

~/usr/bin/zsh
1

# 安装oh-my-zsh

首先配置bash登录跳转zsh,编辑.bash_profile添加一下内容,注意路径!

export PATH=$HOME/usr/bin:$PATH
export SHELL=`which zsh`
[ -f "$SHELL" ] && exec "$SHELL" -l
1
2
3

安装 oh-my-zsh

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
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)
1
2
3
4

如果你在CentOS下面使用,默认提示可能不是灰色的,这里可以在.zshrc文件添加配置(注意放到插件加载之后)

# fg后面的数字可以更改以显示不同的颜色
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=2'
1
2

# 查找当前目录下的文件 FZF (opens new window)

brew install fzf
/usr/local/opt/fzf/install
1
2

安装以后按Ctrl+T可以呼出查找界面.

# 快速跳转目录 -- z (opens new window)

无需安装,直接添加插件即可。

# 编辑 ~/.zshrc 添加插件
plugins=(z)
1
2

例子:

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
2
3
4
5
6
7
8
9

# 配置

# 终端显示前缀

开启多个终端的时候经常分不清楚SSH的机器,可以通过配置~/.zshrc增加终端的前缀。

PROMPT="VPS-"$PROMPT
1

# 我的 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
更新时间: 4/18/2021, 1:21:06 AM