git - 将 Ubuntu 终端更改为类似于 Window 的 Git-bash

标签 git terminal git-bash ubuntu-18.04

有没有办法用 Window 的 Git-bash(外观和行为)更改/替换默认的 Ubuntu 终端?基本上,终端应该显示与当前分支/存储库相关的所有必要信息,就像它在 Window 中所做的那样。

我正在使用 VS Code 并为 Window platform 配置了 Git-Bash .但是找不到任何可以让我在 Ubuntu 平台上实现相同目标的东西。

我已经检查了以下链接以获得答案-

  • Git bash on Ubuntu . -> 更改后,它显示当前分支,但所有整个文本/字符串都变成单调的白色。
  • How can I have a shell for git like in Windows? . -> 只有分支名称的文本颜色保持为绿色,其他一切都变为白色。
  • 最佳答案

    @kostix 建议,我用适当的关键字搜索互联网,发现this question thread然后最后到 this page .在尝试了那里提到的方法后,我最终得到了以下代码,效果更好。在 .bashrc 中添加这些代码文件存在于 Home文件夹。使用 ~/.bashrc/ 找到它命令。

    # git branch info if present
    parse_git_branch() {
         git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
    }
    export PS1="\[\033[36m\]\u@\h\[\033[00m\] \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] \n\[\033[1;31m\]>>\[\033[00m\] "
    

    Ubuntu 的终端截图 -

    enter image description here

    VS Code 的终端截图 -

    enter image description here

    您可以根据您的选择更新代码以更改颜色代码。

    关于git - 将 Ubuntu 终端更改为类似于 Window 的 Git-bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55729985/

    相关文章:

    gradle - 从 gradle 任务执行 git bash

    git - 如何在 Shopware 6 开发系统上管理媒体?提交到 git 还是不提交?

    arrays - 设置名词集时,如何在 Bash 中将 "-@-expand ("${array[@]}") 可能为空数组?

    git - 用 git 或 hub 命令替换 GitHub UI 序列

    Ruby命令行脚本不连续执行代码

    windows - 在 msysgit 中使用 virtualenvwrapper-win (sh.exe": mkvirtualenv: command not found), 在正常的 cmd 中工作

    python - 以编程方式 `git checkout .` 与 dulwich

    Mysql根访问被拒绝

    c - 如何在使用 CTRL-D 退出时让 while 循环中的计数器停止

    git - 如何在 Windows 上更改 Git Bash 的默认位置?