工欲善其事,必先利其器~
1、安装iterm2
-
从官网下载并安装
-
打开iterm2将其设置为默认终端工具:
iTerm2 -> Make iTerm2 Default Term
-
在
Preferences -> Profiles -> Colors -> Color Persers
里面设置自己喜欢的主题格式 -
打开Preferences,选中Keys,勾选Hotkey下的Show/hide iTerm2 with a system-wide hotkey,将热键设置为command+. ,这样你就可以通过command+. 全局热键来打开或关闭iTerm2窗口。
2、选择Shell
2.1、查看所有的Shell
[min@bogon:] ~ $ cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
2.2、查看当前Shell
[min@bogon:] ~ $ echo $SHELL
/bin/bash
2.3、切换Shell
# 切换bash
[min@bogon:] ~ $ chsh -s /bin/bash
# 切换zsh
[min@bogon:] ~ $ chsh -s /bin/zsh
3、配置Bash
3.1、设置配色
执行vim ~/.bash_profile
,在起始位置添加如下两行
export CLICOLOR = 1
export LSCOLOR = Gxfxaxdxcxegedabagacad
配置说明:
CLICOLOR
(Command Line Interface Color)是用来设置是否进行颜色的显示,CLI是的缩写。
LSCOLORS
是用来设置当CLICOLOR
被启用后,各种文件类型的颜色。 LSCOLORS的值中每两个字母为一组,分别设置某个文件类型的文字颜色和背景颜色。 LSCOLORS中一共11组颜色设置,按照先后顺序,分别对以下的文件类型进行设置:
- directory
- symbolic link
- socket
- pipe
- executable
- block special
- character special
- executable with setuid bit set
- executable with setgid bit set
- directory writable to others, with sticky bit
- directory writable to others, without sticky bit
颜色对照表:
a 黑色
b 红色
c 绿色
d 棕色
e 蓝色
f 洋红色
g 青色
h 浅灰色
A 黑色粗体
B 红色粗体
C 绿色粗体
D 棕色粗体
E 蓝色粗体
F 洋红色粗体
G 青色粗体
H 浅灰色粗体
x 系统默认颜色
3.2、命令行提示符
# 仅显示当前目录名
export PS1='\[\e[01;33m\][\[\e[01;32m\]\u\[\e[01;33m\]@\[\e[01;35m\]\h:\[\e[01;33m\]] \[\e[01;36m\]\W \[\e[01;32m\]\$ '
#显示全部路径名
export PS1='\[\e[01;33m\][\[\e[01;32m\]\u\[\e[01;33m\]@\[\e[01;35m\]\h:\[\e[01;33m\]] \[\e[01;36m\]\w \[\e[01;32m\]\$ '
4、配置Zsh
4.1、安装oh-my-zsh
- 查看当前系统支持的sh
min@bogon ~ cat /etc/shells
- 将zsh设置为默认终端
chsh -s /bin/zsh
- 打开iTerm2,安装Oh-My-ZSH
curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
4.2、配置oh-my-zsh
4.2.1、修改主题
打开.zshrc
文件,在ZSH_THEME
字段修改主题,例如修改为:
zsh_THEME="agnoster"
该主题需要字体Meslo的支持,下载安装字体后,在iTerm -> Preferences -> Profiles -> Text
里的Font选择Meslo LG M Regular for Powerline
4.2.2、语法高亮
brew install zsh-syntax-highlighting
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source ~/.zshrc
4.2.3、只显示当前文件夹
当我们文件目录比较深的时候会发现文件夹显示的完整路径过长,影响视觉上的体验。我们可以将~/.oh-my-zsh/themes/agnoster.zsh-theme
里的prompt_dir
字段注释掉,并替换为:
prompt_dir() {
prompt_segment blue black '%1~'
}
4.2.4 修改用户名
PROMPT='%{$fg_bold[red]%}-> %{$fg_bold[magenta]%}%n%{$fg_bold[cyan]%}@%{$fg[green]%}%m %{$fg_bold[green]%}%p%{$fg[cyan]%}%~ %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%}% %{$fg[magenta]%}%(?..%?%1v)%{$fg_bold[blue]%}? %{$fg[yellow]%}# '
网友评论