看别人用zsh开发感觉完全就是一副大佬的样子,教练我也想…
一、zsh安装
声明:zsh 是针对单用户的,哪个用户安装的哪个用户用,其他的用户还是使用的bash
-
查看当前系统的shell
[kino@hdoop102 ~]$ echo $SHELL /bin/bash
-
查看centos的bin下是否有zsh包
[kino@hdoop102 ~]$ cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/dash /bin/tcsh /bin/csh
默认没有zsh
-
安装zsh包
[kino@hdoop102 ~]$ sudo yum -y install zsh [kino@hdoop102 ~]$ cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/dash /bin/tcsh /bin/csh /bin/zsh
-
使用命令
chsh -s /bin/zsh
更换成 SHELL[kino@hdoop102 ~]$ echo $SHELL /bin/bash [kino@hdoop102 ~]$ chsh -s /bin/zsh Changing shell for demo. Password: Shell changed. [kino@hdoop102 ~]$ echo $SHELL /bin/bash
-
重启
[kino@hdoop102 ~]$ reboot
-
重启后准备安装
oh-my-zsh
, 查看当前系统的shell[kino@hdoop102 ~]$ echo $SHELL /bin/zsh
二、oh my zsh
-
安装git环境
[kino@hdoop102 ~]$ sudo yum -y install git [sudo] password for demo:
-
安装
oh my zsh
,有两种安装方式:① 自动安装:
[kino@hdoop102 ~]$ wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh ########################## 如果看的下面的画面表示你成功了 ###################### \033[0;34mLooking for an existing zsh config...\033[0m \033[0;34mUsing the Oh My Zsh template file and adding it to ~/.zshrc\033[0m \033[0;34mCopying your current PATH and adding it to the end of ~/.zshrc for you.\033[0m \033[0;32m __ __ \033[0m \033[0;32m ____ / /_ ____ ___ __ __ ____ _____/ /_ \033[0m \033[0;32m / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ \033[0m \033[0;32m/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / \033[0m \033[0;32m\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ \033[0m \033[0;32m /____/ ....is now installed!\033[0m
② 手动安装
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
-
source
[kino@hadoop103]~% source ~/.zshrc ➜ ~
能看见下图,就是安装成功了
-
编辑主题
➜ ~ sudo vim ~/.zshrc # 编辑 # ZSH_THEME="robbyrussell" ZSH_THEME="ys" # wq! 保存退出 # kino @ hadoop103 in ~ [19:16:20] $
三、autojump插件安装
autojump
这个插件安装之后,zsh会自动记录你访问过的目录,通过j + 目录名可以直接进行目录跳转,而且目录名支持模糊匹配和自动补全,例如你访问过hadoop-1.0.0目录,输入j hado即可正确跳转。j –s可以看你的历史路径库,安装方法如下:
-
下载
autojump
# kino @ hadoop103 in ~ [19:16:20] $ wget https://github.com/downloads/joelthelion/autojump/autojump_v21.1.2.tar.gz 正在解析主机 github.com... 13.250.177.223 正在连接 github.com|13.250.177.223|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 301 Moved Permanently 位置:https://github.com/downloads/wting/autojump/autojump_v21.1.2.tar.gz [跟随至新的 URL] --2019-09-25 19:22:38-- https://github.com/downloads/wting/autojump/autojump_v21.1.2.tar.gz 正在连接 github.com|13.250.177.223|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 302 Found 位置:https://github.s3.amazonaws.com/downloads/wting/autojump/autojump_v21.1.2.tar.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20190925%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190925T112241Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=2d450aabb2e8df86534e0462f1bd8abbbac577cb3e7452da490593ad78d83816 [跟随至新的 URL] --2019-09-25 19:22:41-- https://github.s3.amazonaws.com/downloads/wting/autojump/autojump_v21.1.2.tar.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20190925%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190925T112241Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=2d450aabb2e8df86534e0462f1bd8abbbac577cb3e7452da490593ad78d83816 正在解析主机 github.s3.amazonaws.com... 52.216.178.91 正在连接 github.s3.amazonaws.com|52.216.178.91|:443... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:53434 (52K) [application/gzip] 正在保存至: “autojump_v21.1.2.tar.gz” 95% [==========================================================================================================> ] 50,774 12.4K/s eta(英国中部时100%[================================================================================================================>] 53,434 13.0K/s in 4.0s 2019-09-25 19:22:48 (13.0 KB/s) - 已保存 “autojump_v21.1.2.tar.gz” [53434/53434])
-
安装
解压autojump_v21.1.2.tar.gz
并进入 解压后的目录中执行$ ./install.sh Installating autojump... Destination: /home/kino/.autojump/ Binary: /home/kino/.autojump/bin/ Documentation: /home/kino/.autojump/share/man/man1/ Icon: /home/kino/.autojump/share/autojump/ Shell scripts: /home/kino/.autojump/etc/profile.d/ zsh functions: /home/kino/.autojump/functions "./bin/icon.png" -> "/home/kino/.autojump/share/autojump/icon.png" "./bin/jumpapplet" -> "/home/kino/.autojump/bin/jumpapplet" "./bin/autojump" -> "/home/kino/.autojump/bin/autojump" "./bin/autojump_argparse.py" -> "/home/kino/.autojump/bin/autojump_argparse.py" "./docs/autojump.1" -> "/home/kino/.autojump/share/man/man1/autojump.1" "./bin/autojump.sh" -> "/home/kino/.autojump/etc/profile.d/autojump.sh" "./bin/autojump.bash" -> "/home/kino/.autojump/etc/profile.d/autojump.bash" "./bin/autojump.zsh" -> "/home/kino/.autojump/etc/profile.d/autojump.zsh" 已删除"/home/kino/.autojump/functions/_j" "./bin/_j" -> "/home/kino/.autojump/functions/_j" Please add the line to ~/.zshrc : [[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh You need to run 'source ~/.zshrc' before you can start using autojump. To remove autojump, run './uninstall.sh'
-
配置
编辑~/.zshrc
vim ~/.zshrc # 添加 [[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh
-
让配置生效
执行:source ~/.zshrc
-
卸载
如果想要卸载 autojump,执行:./uninstall.sh
-
基本使用
autojump pattern
说明:
① autojump 可以缩写为 j
② pattern 是要跳转的目录的模糊匹配 -
例子:
如果经常使用一个目录为:/home/kino/autojump_v21.1.2
那么就可以写成:j au
j 是 autojump 的缩写
au 是 autojump_v21.1.2 目录的缩写 -
说明
刚刚安装上是不能直接使用的, autojump 不知道你进程使用的目录是哪些,多重复使用使用cd 目录
就可以使用 autojump 了 -
如果刚安装想直接使用,手动添加路径:
j -a 目录
# kino @ hadoop102 in ~ [0:52:54] C:1 $ j -a /opt/module/kafka # kino @ hadoop102 in ~ [0:53:20] $ j ka /opt/module/kafka # kino @ hadoop102 in /opt/module/kafka [0:53:23] $
-
autojump 帮助
# kino @ hadoop102 in ~/autojump_v21.1.2 [0:40:11] $ j -h usage: autojump [-h] [-a DIR] [-b] [--complete] [--purge] [-s] [--version] [DIR [DIR ...]] Automatically jump to directory passed as an argument. positional arguments: DIR directory to jump to optional arguments: -h, --help show this help message and exit -a DIR, --add DIR manually add path to database -b, --bash enclose directory quotes to prevent errors --complete used for tab completion --purge delete all database entries that no longer exist on system -s, --stat show database entries and their key weights --version show version information and exit Please see autojump(1) man pages for full documentation.