oh-my-zsh自定义配置

oh-my-zsh主题配置

默认的zsh主题robbyrussell已经很棒了, 简洁高效, 能很好的显示git的相关信息, 好比branch信息, 修改, 删除, 添加等操做. 可是多用户的话就不能很好的展现, 咱们能够经过修改robbyrussell的配置文件来达到咱们想要的效果.git

通常状况下, 咱们安装oh-my-zsh都是在本身的家目录下~, 因此咱们就以家目录为例.code

编辑~/.oh-my-zsh/themes/robbyrussell.zsh-theme这个文件:it

local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'

ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"

local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"修改成local ret_status="%(?:%{$fg_bold[yellow]%}${USER} %{$fg_bold[green]%}➜ :%{$fg_bold[yellow]%}${USER} %{$fg_bold[red]%}➜ )"zsh

以下:配置

local ret_status="%(?:%{$fg_bold[yellow]%}${USER} %{$fg_bold[green]%}➜ :%{$fg_bold[yellow]%}${USER} %{$fg_bold[red]%}➜ )"
PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'

ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"

这样当使用su切换时用户名仍是原来的, 添加一个判断:终端

if [ `id -u` -eq 0 ];then
    local ret_status="%(?:%{$fg_bold[yellow]%}root %{$fg_bold[green]%}➜ :%{$fg_bold[yellow]%}root %{$fg_bold[red]%}➜ )"
else
    local ret_status="%(?:%{$fg_bold[yellow]%}${USER} %{$fg_bold[green]%}➜ :%{$fg_bold[yellow]%}${USER} %{$fg_bold[red]%}➜ )"
fi
PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'

ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"

保存退出, 在终端中执行source .zshrc让配置生效.配置文件

样式为"root ➜ ~".样式

相关文章
相关标签/搜索