gpt4 book ai didi

Ubuntu 上的 Git bash

转载 作者:行者123 更新时间:2023-12-04 18:32:12 26 4
gpt4 key购买 nike

如何像在 Windows Bash 中一样将分支名称添加到控制台行

foo@bar MINGW64 /d/_GitRepo/game (master)
$

并更改颜色主题

最佳答案

如果您只想在终端命令行中显示当前分支,此站点可以帮助您 https://techcommons.stanford.edu/topics/git/show-git-branch-bash-prompt

总结一下:

将此功能放入您的.bashrc

function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

它提取当前分支。
然后编辑 PS1 变量的值并调用您使用 $(parse_git_branch) 创建的函数.它应该类似于:
PS1="\h:\W \u$BLUE\$(parse_git_branch) $DEFAULT\$"

关于Ubuntu 上的 Git bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34769621/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com