如题,服务器 hostname 非常长,想在 oh my zsh 的显示中隐藏掉但是还想显示出用户名称。试了命令
prompt_context() {
prompt_segment black default "%(!.%{%F{yellow}%}.)%n"
}
会一直报错:
prompt_context:1: command not found: prompt_segment
查了一下也没有什么有效的解决方法,大家有没有遇到过类似的问题以及如何解决的?
1
f1ush 1 天前
换个主题?
|
![]() |
3
augus 1 天前
编辑现在用的主题?删掉不需要的。
|
4
JasonEWNL 1 天前 ![]() 1. 找到本地的配置文件(比如 classic 风格就是 p10k-classic.zsh ,具体文件夹按照官方安装一般在 ~/.oh-my-zsh/custom/themes/powerlevel10k );
2. 定位到有 %n@%m 这样的部分(参考线上比如 https://github.com/romkatv/powerlevel10k/blob/master/config/p10k-classic.zsh#L935 ); 3. 改成 %n 后重开终端则只显示用户名(%n 指代用户名,%m 指代主机名)。 |
![]() |
5
MasterCai OP @JasonEWNL
感谢大佬,我在`~/.oh-my-zsh/custom/themes/powerlevel10k/config/p10k-classic.zsh`路径找到了配置文件,修改了 [L931-L935]( https://github.com/romkatv/powerlevel10k/blob/8fa10f43a0f65a5e15417128be63e68e1d5b1f66/config/p10k-classic.zsh#L931C1-L935C51) 所有的`%n@%m` 为 `%n` 然后退出 ssh 后重新登录,包括重新 source 都不生效,您能再给点排查建议嘛 |
6
xxb 1 天前
~/.zshrc :
# 设置自定义的 PROMPT,如 PROMPT='%n %~ %(!.#.$) ' |
8
JasonEWNL 1 天前 ![]() 若是改具体风格的不行,直接修改 ~/.p10k.zsh (内容与之前一致)也行,改完 source ~/.p10k.zsh 生效。
|
![]() |
12
zhj9709 1 天前 ![]() # PS1
export PS1='%(?:%{$fg_bold[green]%}%n@%m:%{$fg_bold[red]%}%n@%m) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)' 这是我用的 PS1 ,里面的%m 就是主机名,自己换掉就行了 |
![]() |
13
zhj9709 1 天前
|