OSX
安装 zsh
# 方式一:
$ brew install zsh
# 切换默认 $SHELL
$ chsh -s /bin/zsh
# 切换回来
$ chsh -s /bin/bash
# 方式二: curl 代码库克隆到 ~/.oh-my-zsh 下
$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Note: 默认 Shell 启用 zsh 后,环境变量等相关配置就要到
~/.zshrc
、/etc/zshrc
,而非~/.bashrc
、/etc/bashrc
了。
安装 iterm2
# cask 安装第三方库中的软件
$ brew cask install iterm2
# after 2021
$ brew install --cask iterm2
# 下载配色
$ mkdir ~/.iterm2 && cd ~/.iterm2
$ git clone https://github.com/mbadolato/iTerm2-Color-Schemes
# 导入配色
Preferences -> Profiles -> Color Presets -> Import -> ~/.iterm2/iTerm2-Color-Schemes/schemes
# 选定配色
Preferences -> Profiles -> Color Presets -> Batman
安装 Non ASCII 图标字体
# 添加第三方字体库
$ brew tap homebrew/cask-fonts
# 安装字体
$ brew cask install font-hack-nerd-font
# 启用 non-ASCII text
Iterm2 -> Preferences -> Profiles -> -> Text -> Font -> Use a different font for non-ASCII text
# 设置字体
Hack Nerd Font Mono / Italic / Font Size 13 / v|i 100 n|n 101
安装 zsh 主题
# 下载主题
$ git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
# 配置 zsh
$ vim ~/.zshrc
# 配置主题
ZSH_THEME="powerlevel9k/powerlevel9k"
# 设置 powerlevel9k 的字体为之前下载的 non ascii 字体
POWERLEVEL9K_MODE="nerdfont-complete"
# 自定义命令行左边元素
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(ssh dir vcs newline status)
# 删掉命令行右边元素
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
# 命令前加换行,这样输入的命令就会在另一行
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
$ source ~/.zshrc
zsh plugins
# 代码自动提示,当自动提示出现后,按 ➡ (右方向键)就能把自动提示的命令输入到当前的 Terminal
$ brew install zsh-autosuggestions
# 查看说明
$ brew info zsh-autosuggestions
# 启用插件
$ echo "source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc
$ source ~/.zshrc
# 彩色高亮 ls
$ gem install colorls
# 改别名
$ echo "alias ls='colorls'" >> ~/.zshrc
$ echo "alias ll='ls -l'" >> ~/.zshrc
$ echo "alias grep='grep --color=auto'" >> ~/.zshrc
$ source ~/.zshrc
zsh common plugins enable
$ cd ~/.oh-my-zsh/custom/plugins
$ git clone https://github.com/paulirish/git-open
$ git clone https://github.com/zsh-users/zsh-autosuggestions
$ git clone https://github.com/zsh-users/zsh-syntax-highlighting
$ vim ~/.zshrc
plugins=(
git
zsh-syntax-highlighting
zsh-autosuggestions
git-open
)
$ source ~/.zshrc
VSCode Font
"terminal.integrated.fontFamily": "Hack Nerd Font Mono",
"terminal.integrated.fontSize": 14,
iterm2 空闲链接不断开
Prerferences -> Profiles -> Session -> Check `When idle, send ASCII code ...`
sudo su
# 通过 sudo su 登陆其他用户的时候保持 zsh
$ sudo su -s /bin/zsh anotheruser
修改 PROMOT
- zsh 终端用户名设置(PS1)
$ cd ~/.oh-my-zsh/themes $ echo $ZSH_THEME robbyrussell # 复制一份自定义主题,避免更新导致被覆盖 $ cp robbyrussell.zsh-theme myrobbyrussell.zsh-theme $ vim myrobbyrussell.zsh-theme # %n 当前登陆名称 PROMPT="%n %(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"