Mac终端改造

平时Mac使用的shell使bash, 它虽然能满足我们的需要, 但是使用起来不是很方便. zsh可配置性强, 用户可以自定义配置, 个性化强.

更换shell

查看当前使用的shell

echo $SHELL

1
/bin/bash

查看系统当前内置的shell

cat /etc/shells

1
2
3
4
5
6
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh

如果没有发现/bin/zsh, 就需要手动安装Zsh.

替换shell

chsh -s /bin/zsh

1
2
Changing shell for **.
Password for **: your password

重启

echo $SHELL

1
/bin/zsh

替换成功!

安装oh-my-zsh

oh-my-zsh用来管理Zsh配置的.

安装

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to ~/.zshrc
__ __
____ / /_ ____ ___ __ __ ____ _____/ /_
/ __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \
/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / /
\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/
/____/ ....is now installed!

Please look over the ~/.zshrc file to select plugins, themes, and options.

p.s. Follow us at https://twitter.com/ohmyzsh.

p.p.s. Get stickers and t-shirts at https://shop.planetargon.com.

更改配置

vim ~/.zshrc

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
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="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"

# Which plugins would you like to load?
# Standard 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.
plugins=(
git
)

source $ZSH/oh-my-zsh.sh

以上是部分配置, 需将#删除才能生效. 键入i进入编辑模式, 修改后esc退出编辑模式, 键入:wq保存退出. oh-my-zsh有支持的主题插件, 可以自由配置.

插件推荐

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

修改配置(zsh-syntax-highlighting)

vim ~/.zshrc

1
2
3
plugins=(
git zsh-syntax-highlighting
)

让修改生效(zsh-syntax-highlighting)

source ~/.zshrc

zsh-autosuggestions

安装zsh-autosuggestions

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

修改配置(zsh-autosuggestions)

vim ~/.zshrc

1
2
3
plugins=(
git zsh-autosuggestions zsh-syntax-highlighting
)

让修改生效(zsh-autosuggestions)

source ~/.zshrc

好了, 打完收工!

------------- The End -------------
显示评论