写到这一篇才算是写到了真正重要的东西。
我们要用的终端配置是 iTerm2 + oh-my-zsh + Solarized Dark Higher Contrast 配色
iterm2与配色
首先去iterm2官网下载 iterm2,然后下载 Solarized Dark Higher Contrast 配色文件
打开偏好设置
关闭 Closing 里面的两个提示选项和Selection中的Copy to pasteboard on selection
Advanced->Add status bar icon when exclude from dock?改为 yes
Appearance 勾选 stretch tabs to full bar System->Exclude from Dock and Application Switcher
Profile 下 Colors->color presets Import刚才下载的配色文件,然后选择Solarized Dark Higher Contrast text 下 Cursor 选择 Vertical Bar 取消勾选Draw bold text in bright colors Window下Style 选择 Top of Screen,勾选Hide after Opening
Terminal 下 选择 Unlimited Scrolback、Slience bell 取消Show bell icon in tabs
keys 下开启全局快捷键
安装 Homebrew
开局先装包管理器,按照官网的脚本,一行命令搞定
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
安装 zsh
Mac下已经默认是zsh了,如果你是linux,使用相应的包管理器安装
ubuntu 下使用
sudo apt install zsh
安装oh-my-zsh
如果你希望使用跟我一样的配置可以直接使用GitHub - shenmishajing/Setting-for-Mac 中的脚本一键安装,那么之后的内容你可以只看一下我的配置里有什么,都不需要手动配置了。
如果你希望自己手动安装并进行配置,你使用下面的命令安装
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
开启自动更新
添加如下代码到zshrc中
# Automatically upgrade oh-my-zsh without prompting me
DISABLE_UPDATE_PROMPT=true
主题
安装字体
根据官网的描述安装相应的字体,如果你在用iTerm2,你可以跳过这一步,因为powerlevel10k可以帮你自动安装这个字体
安装 powerlevel10k 主题
按照官网教程,使用以下命令安装
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
用vim打开隐藏文件 .zshrc ,修改主题为 agnoster:
ZSH_THEME="powerlevel10k/powerlevel10k"
之后首次开启终端时,powerlevel10k会让你简单地配置一下,根据喜好选择即可。
powerlevel10k的配置文件.p10k.zsh默认在home目录下,你也可以自己移动一下
mv .p10k.zsh $ZSH_CUSTOM/themes/powerlevel10k/
然后自己手动修改一下.zshrc
# To customize prompt, run `p10k configure` or edit $ZSH_CUSTOM/themes/powerlevel10k/.p10k.zsh.
[[ ! -f $ZSH_CUSTOM/themes/powerlevel10k/.p10k.zsh ]] || source $ZSH_CUSTOM/themes/powerlevel10k/.p10k.zsh
zsh 插件
统一安装
# zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# fast-syntax-highlighting
git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git \
${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting
# zsh-history-substring-search
git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
然后在oh-my-zsh中启用
找到
plugins=()
修改为
plugins=(
copypath
copyfile
sudo
git
z
zsh-history-substring-search
zsh-autosuggestions
fast-syntax-highlighting
)
export ZSH_COMPDUMP=$ZSH/cache/.zcompdump-${HOST}-${ZSH_VERSION}
设置ZSH_COMPDUMP变量是为了将.zcompdump文件挪到zsh的cache目录下而非home目录里。完成后再向.zshrc中添加如下代码
bindkey '^p' history-substring-search-up
bindkey '^n' history-substring-search-down
# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}
pastefinish() {
zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish
# set proxy
export proxy_ip='localhost'
export proxy_port='7890'
alias sp='export https_proxy=http://$proxy_ip:$proxy_port http_proxy=http://$proxy_ip:$proxy_port all_proxy=socks5://$proxy_ip:$proxy_port'
# unset proxy
alias up='unset all_proxy&&unset https_proxy&&unset http_proxy'
# echo proxy
alias ep='echo "http_proxy=$http_proxy\nhttps_proxy=$https_proxy\nall_proxy=$all_proxy"'
# use proxy in terminal
sp
自动提示命令zsh-autosuggestions
当你重新打开终端的时候可能看不到变化,可能你的字体颜色太淡了,我们把其改亮一些:
移动到 ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions 路径下cd ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
用
vim
打开zsh-autosuggestions.zsh
文件,修改ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=10'
命令历史搜索zsh-history-substring-search
使用ctrl-p与ctrl-n即可上下搜索命令历史,支持匹配历史命令的中间部分而不仅仅只能匹配开头
自动跳转zsh-z
根据以前的访问记录自动跳转到匹配的路径
copypath与copyfile
在命令行中直接敲入这两个命令可以将当前路径或文件内容复制到粘贴板
sudo
双击ESC在当前命令开头添加或删除sudo
终端工具
使用包管理器安装lsd,bat,dust,fd,ripgrep,duf,lf。如果你在用Mac,可以直接使用homebrew一键安装
brew install lsd bat dust fd ripgrep duf lf
更多命令见modern-unix仓库
lsd:ls替代品
bat:cat代替品
dust:du代替品
fd:find代替品
ripgrep:grep代替品
duf:du代替品
lf:终端文件浏览器