我目前正在使用以下命令显示目录路径和 git 分支PS1
:
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
这是提示:
john@myMac /Volumes/.../.../.../MyProject (master) $
但是由于我的完整路径(显示\w\[\033[33m\]
的很长,我只想显示文件名...
john@myMac MyProject (master) $
没有这样的选择PS1
......有可能吗?
感谢反馈
您可以使用\W
代替\w
:
export PS1="\u@\h \[\033[32m\]\W\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
根据man bash
:
\w the current working directory, with $HOME abbreviated with a tilde
(uses the value of the PROMPT_DIRTRIM variable)
\W the basename of the current working directory, with $HOME abbreviated with a tilde
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句