如何让 Linux 终端看起来像 Windows Git Bash?

如何让 Linux 终端看起来像 Windows Git Bash?

在有人说之前,是的,我知道这是重复的,除了当我将该代码复制/粘贴到 中时tilde slash period bash(no period)rc,终端根本没有改变。

我在 Virtual Box (Windows 10) 上运行 Debian。我猜我正在使用 Mate 桌面,因为我使用的是 Mate 终端。

当我使用 git 进入目录时,我需要输入 git status 或 gitbranch 来查看我所在的分支,它不会像代码中那样显示它。

编辑:我粘贴的代码

force_color_prompt=yes
parse_git_branch() {
 git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
 PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi
unset color_prompt force_color_prompt

编辑2:事实证明我的.bashrc文件有

 if [ "$color_prompt" = yes ]; then
     PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
    else
     PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
    fi
    unset color_prompt force_color_prompt

打印在它的其他地方。我评论了这一点,现在当我在 git 目录中时,我不需要输入git branch或就可以得到分支(无论什么) git status。我现在遇到的问题是颜色不会显示。这不是一个主要问题,但如果有的话那就太好了。

答案1

您可能需要再次获取该文件。注销或执行以下操作:

source ~/.bashrc

答案2

可能是您缺少PS1用户 ID 的提示配置。
你可能可以使用它具有这些功能以及更多功能。

更新
这是我的PS1bash shell 提示符,其中添加了颜色转义序列:

export PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\[\033[1;36m\]\$(parse_git_branch)\[\033[00m\]\n\$ "

相关内容