答案 0 :(得分:2)
如果您想保留现有 linux 终端的相同颜色并显示当前的 git 分支,您可以将以下内容添加到您的默认 PS1。
PS1 基本上告诉你的 bash 提示显示什么。 参考:How to Change / Set up bash custom prompt (PS1) in Linux
我使用的是 Ubuntu 20.04,默认 PS1 位于 ~/.bashrc 文件中的 if [ "$color_prompt" = yes ]; then
下。
步骤:
if [ "$color_prompt" = yes ]; then
#show git branch
show_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[00m\] \[\033[31m\]\$(show_git_branch)\[\033[00m\]$ "
else
PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w \$(show_git_branch)\$ "
fi
整个事情应该是这样的:
#show git branch
show_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[00m\] \[\033[31m\]\$(show_git_branch)\[\033[00m\]$ "
else
PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w \$(show_git_branch)\$ "
fi
它应该是这样的: Terminal with git branch
答案 1 :(得分:0)
如果您使用的是bash,
我在〜/ .bashrc中使用以下内容:
show_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\[\033[0;37m\]\u@\h\[\033[0;37m\] \w \[\033[31m\]\$(show_git_branch)\[\033[00m\]$\[\033[00m\] "
它的样子:
您只需将代码添加到.bashrc文件中并运行source ~/.bashrc
。
答案 2 :(得分:-1)
我正在使用oh-my-zsh在macOS
中实现相同功能,因为Linux
也可以使用bash
,但您可以尝试尝试从zsh
切换到sap.ui.xmlfragment("firstapp.flightdata.view." + wa[j].getAttribute("value"), this).placeAt(wa[j].getAttribute("id"));
{1}}。