我只是想在我的新Mac上更新我的.bashrc和.bash_profile文件,我的文件看起来是这样的。
/ .bash_rc
orange=$(tput setaf 166);
yellow=$(tput setaf 228);
green=$(tput setaf 71);
white=$(tput setaf 15);
bold=$(tput bold);
reset=$(tput sgr0);
PS1="\[${bold}\]\n";
PS1+="\[${orange}\]\u"; # username
PS1+="\[${white}\] at ";
PS1+="\[${yellow}\]\h"; # host
PS1+="\[${white}\] in ";
PS1+="\[${green}\]\W :"; # working directory
PS1+="\n";
PS1+="\[${white}\]\$ \[${reset}\]"; # '$' and reset color
export PS1;
/ .bash_profile
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
我不知道我输入错了什么。感谢任何帮助。谢谢你的帮助。
首先,你使用的是 zsh
,不 bash
;提示的配置完全不同。
第二,你不需要导出 PS1
因为任何关心其价值的过程都会采购 .zshrc
.
下面的内容应该可以用,放在 .zshrc
:
# The variables aren't necessary, but retained for
# ease of updating. You could specify %F{15} directly
# for %F{$white}, e.g.
orange=166
yellow=228
green=71
white=15
PS1=$'%B\n'
PS1+="%F{$orange}%n"
PS1+="%F{$white} at "
PS1+="%F{$yellow}%m";
PS1+="%F{$white} in "
PS1+="%F{$green}%~ :"
PS1+=$'\n'
PS1+="%F{$white}%# %f%b"
%B
和 %b
分别开启和关闭粗体。%F{...}
改变当前前景色。%f
重置为终端默认值。键盘上的 \
逃出 bash
被替换为 %
逃跑。你不需要 zsh
相当于 \[...\]
任何地方,因为你没有使用任何原始字节序列来控制格式。
整个事情可以简化为一行。
PS1=$'%B\n%F{166}%n%F{15} at %F{228}%m%F{15} in %F{71}%~ :\n%F{15}%# %f%b'
虽然较长的版本更容易维护。
最后,请注意(与 bash
) zsh
来源 .zshrc
为所有交互式外壳。如果它也是一个登录的shell,它的来源是 .zprofile
,之前,而不是代替。.zshrc
.