默認的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 ➜ ~
".樣式