使用強大的 shell--zsh
成果圖
顏色取決於終端, 我用的是 iTem2 中的 SeaShells 主題
資源
- oh-my-zsh 樣式預覽
- mac 配置 iTem2 和 zsh
- linux 配置 zsh
- MAC更新Sed
正文
命令
改變 shell: chsh -s <shell_bin>
查看系統內的 shell: cat /etc/shells
查看當前的 shell: echo $SHELL
, 通常默認值為 /bin/bash
友情提示: 修改配置文件後需要 source ~/.zshrc
或重啟.
安裝與基礎配置
- 想辦法安裝上 zsh ( 包管理器, 複製 bin 文件等方式 ), 通常安裝位置為 /bin/zsh.
- 依照上述命令改變 shell.
- 重啟, 可能會出現一個歡迎界面, 直接退出即可, 配置文件在後面主題中設置.
使用主題 oh-my-zsh
- 下載 oh-my-zsh
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
- 複製默認 zsh 配置文件
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
- 修改 ~/.zshrc 中的 ZSH_THEME, 樣式可在上述資源中預覽, 我選擇了 agnoster
使用自動提示和高亮插件
- 插件名為
zsh-autosuggestions
和zsh-syntax-highlighting
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone git://github.com/zsh-users/zsh-syntax-highlighting $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
- 修改 ~/.zshrc 中的 plugins
plugins=(
zsh-syntax-highlighting
zsh-autosuggestions
git
)
安裝其他插件步驟如上
優化
- 刪除注釋 ( mac 需要使用 gsed 代替, 具體參考開頭資源 )
sed -i /^#/ d ~/.zshrc && sed -i /^$/ d ~/.zshrc
- 更改 user@machine 的值
改變 ~/.oh-my-zsh/themes/agnoster.zsh-theme 中的內容
prompt_context() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m"
fi
}
將上述內容中 %n@%m 換成任意值比如 mac, aliyun 等等
- 將 bash 中的配置移入
cat ~/.bash_profile >> ~/.zshrc
推薦閱讀: