【问题标题】:hiding name@name-macbook-air from iterm2 on mac os x在 mac os x 上从 iterm2 隐藏 name@name-macbook-air
【发布时间】:2016-04-29 23:59:32
【问题描述】:

正如问题的标题所说的那样。我的终端中有name@name-macbook-air。我想隐藏这一点。我试过了。

export PS1="\W \$" // Does not work even after restarting iterm

// this works but it always put $ but I want full path too but no username and computer name
echo "export PS1='$ '" >> ~/.bash_profile
. ~/.bash_profile

// This only put '\W' but no directory path
echo "export PS1='\W \$ '" >> ~/.bash_profile
. ~/.bash_profile

如何隐藏 name@name-macbook-air?

更新

当我执行echo $PS1 时,我会得到以下输出

%{%f%b%k%}$(build_prompt)

我正在使用 oh-my-zsh。

【问题讨论】:

  • 不完全是您要查找的内容,但您可以显示name 而不是name@name-macbook-air,方法是将此行放入您的~/.zshrcDEFAULT_USER=name,其中name == whoami

标签: macos shell terminal zsh iterm2


【解决方案1】:

这是我的。它显示完整路径,除非您位于当前用户的主文件夹中。

export PS1="%~ #%b "

【讨论】:

  • 将它添加到 .zshrc 但是它正在工作,但现在我的 oh-my-zsh 似乎无法正常工作。它不再突出显示路径。
  • 这适用于我的 oh-my-zsh 配置:PROMPT="%~ $ "
  • 它确实有效,但我的 zsh 主题没有突出显示路径。
【解决方案2】:

如果高亮是指不同的颜色,试试这个:

local blue="%{$fg_bold[blue]%}"
local reset="%{$reset_color%}"
local current_dir_color=$blue
local current_dir="%~"
local current_dir_output="$current_dir_color$current_dir$reset"

PROMPT='$current_dir_output%1(j. [$jobs_bg].) %#$reset '

【讨论】:

    猜你喜欢
    • 2013-01-12
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 2012-11-27
    • 2019-12-25
    • 2015-02-22
    相关资源
    最近更新 更多