fre*_*rik 3 bash windows-subsystem-for-linux
我~/.bash_profile在“Windows 上的 Ubuntu 上的 Bash”中添加了这个(我已经git安装了):
# Get the Git branch
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
# Custom bash prompt
#
# Includes custom character for the prompt, path, and Git branch name.
#
# Source: kirsle.net/wizards/ps1.html
export PS1="\n\[$(tput bold)\]\[$(tput setaf 5)\] \[$(tput setaf 6)\]\w\[$(tput setaf 3)\]\$(parse_git_branch) \[$(tput sgr0)\]"
Run Code Online (Sandbox Code Playgroud)
进入新的 bash shell 时,我看不到此更改生效。我究竟做错了什么?
我~/.bashrc的未受影响并处于默认状态。
如果我将上面的代码添加到~/.bashrc,它就可以工作。但我不想破坏自定义。
在“Windows 上的 Ubuntu 上的 Bash”中,打开的 shell 不是“登录 shell”,这意味着.bash_profile没有被读取,正如@Zanna 所提到的(谢谢!)。
您可以使用shopt来查看您是否在“登录外壳”中:
shopt login_shell
Run Code Online (Sandbox Code Playgroud)
由于我希望保持整洁并将自定义内容放入自己的文件中,因此我现在从.bashrc以下位置获取自定义文件:
. ~/.bashrc_customizations
Run Code Online (Sandbox Code Playgroud)