
默认的zsh主题robbyrussell已经很棒了,简洁高效,能很好的显示git的相关信息,比如branch信息,修改,删除,添加等 *** 作. 但是多用户的话就不能很好的展示,我们可以通过修改robbyrussell的配置文件来达到我们想要的效果.
一般情况下,我们安装oh-my-zsh都是在自己的家目录下~,所以我们就以家目录为例.
编辑~/.oh-my-zsh/themes/robbyrussell.zsh-theme这个文件:
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]%}? )"
如下:
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]%}? )"fiPROMPT='${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 ? ~".
以上是内存溢出为你收集整理的oh-my-zsh自定义配置全部内容,希望文章能够帮你解决oh-my-zsh自定义配置所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)