Linux下配置zsh和oh my zsh方法。

0. bash和zsh互相切换

bash切换zsh:

1
chsh -s /bin/zsh

zsh切换bash:

1
chsh -s /bin/bash

1. 安装Oh My zsh

使用如下命令克隆Oh My zsh项目:

1
git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh

复制到ZShell文件夹下:

1
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

2. 设置主题

可以在~/.oh-my-zsh/themes中寻找合适的主题,也可以自定义主题。
自定义主题的示例,新建~/.oh-my-zsh/themes/mytheme.zsh-theme,填入如下内容(以下内容仅为参考,可自己定义):

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
CRUNCH_BRACKET_COLOR="%{$fg[white]%}"
CRUNCH_TIME_COLOR="%{$fg[cyan]%}"
CRUNCH_RVM_COLOR="%{$fg[magenta]%}"
CRUNCH_DIR_COLOR="%{$fg[cyan]%}"
CRUNCH_GIT_BRANCH_COLOR="%{$fg[green]%}"
CRUNCH_GIT_CLEAN_COLOR="%{$fg[green]%}"
CRUNCH_GIT_DIRTY_COLOR="%{$fg[red]%}"
CRUNCH_SYMBOL_COLOR="%{$fg[yellow]%}"

# These Git variables are used by the oh-my-zsh git_prompt_info helper:
ZSH_THEME_GIT_PROMPT_PREFIX="$CRUNCH_BRACKET_COLOR:$CRUNCH_GIT_BRANCH_COLOR"
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_CLEAN=" $CRUNCH_GIT_CLEAN_COLOR✓"
ZSH_THEME_GIT_PROMPT_DIRTY=" $CRUNCH_GIT_DIRTY_COLOR✗"

# Our elements:
CRUNCH_TIME_="$CRUNCH_BRACKET_COLOR{$CRUNCH_SYMBOL_COLOR"zsh"$CRUNCH_TIME_COLOR%T$CRUNCH_BRACKET_COLOR}%{$reset_color%}"
ZSH_THEME_RUBY_PROMPT_PREFIX="$CRUNCH_BRACKET_COLOR"["$CRUNCH_RVM_COLOR"
ZSH_THEME_RUBY_PROMPT_SUFFIX="$CRUNCH_BRACKET_COLOR"]"%{$reset_color%}"
CRUNCH_RVM_='$(ruby_prompt_info)'
CRUNCH_DIR_="$CRUNCH_DIR_COLOR%~\$(git_prompt_info) "
CRUNCH_PROMPT="$CRUNCH_BRACKET_COLOR➭ "

# Put it all together!
PROMPT="$CRUNCH_TIME_$CRUNCH_RVM_$CRUNCH_DIR_$CRUNCH_PROMPT%{$reset_color%}"

编辑~/.zshrc文件中主题的位置ZSH_THEME=$theme_name,修改为:

1
2
echo -e "\e[33m φ(≧ω≦*)♪\e[0m \e[36m Welcome to\e[0m \e[36m zsh !!\e[0m" #此处为欢迎语可以不填
ZSH_THEME="mytheme"

并将以下注释取消以禁用自动更新:

1
# zstyle ':omz:update' mode disabled  # disable automatic updates