oh-my-zsh提示符显示当前用户名和主机名

1. 复制当前的agnoster.zsh-theme主题,新名称myagnoster.zsh-theme

sudo cp $ZSH/themes/agnoster.zsh-theme $ZSH/themes/myagnoster.zsh-theme

2. 编辑$ZSH/themes/myagnoster.zsh-theme

sudo nano $ZSH/themes/myagnoster.zsh-theme

prompt_context{}部分:

prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
       prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m"
  fi
}

改为

prompt_context() {
prompt_segment black default "%(!.%{%F{yellow}%}.)$USER"
}

如果要显示主机名就改为

prompt_context() {
prompt_segment black default "%(!.%{%F{yellow}%}.)$USER%m"
}

3. 修改~/.zshrc

ZSH_THEME="myagnoster"

然后使其生效:

source ~/.zshrc

参考文献:
How do I hide the “user@hostname” info · Issue #39 · agnoster/agnoster-zsh-theme

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章