默认的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 ➜ ~
".样式