我目前正在使用PS1
显示目录路径和git分支:
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
中没有这样的选项......有可能吗?
感谢您的反馈
答案 0 :(得分:1)
您可以使用\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
答案 1 :(得分:0)
削减$ PWD:
export PS1="\u@\h \[\033[32m\]${PWD##*/}\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "