简体   繁体   English

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

[英]Change Ubuntu terminal to look like Git-bash of Window

Is there a way to change/replace the default Ubuntu terminal with Git-bash(look and behavior) of Window? 有没有一种方法可以用Window的Git-bash(外观和行为)来更改/替换默认的Ubuntu终端? Basically, the terminal should display all the necessary information related with current branch/repo, just like it does in Window. 基本上,终端应该显示与当前分支/仓库有关的所有必要信息,就像在Window中一样。

I am using VS Code and had configured Git-Bash with it for Window platform . 我正在使用VS Code,并已将其配置为Window平台的 Git-Bash。 But couldn't find anything which would let me achieve the same on Ubuntu platform. 但是找不到任何可以让我在Ubuntu平台上实现相同目标的东西。

I have checked following links for answers - 我已经检查了以下链接的答案-

  1. Git bash on Ubuntu . Ubuntu上的Git bash -> After changes, it shows current branch but all entire text/string becomes monotonous white. ->更改后,它显示当前分支,但所有整个文本/字符串变成单调的白色。
  2. How can I have a shell for git like in Windows? 我如何在Windows中拥有git的外壳? . -> Only branch name's text-color remains as green and everything else becomes white. ->只有分支名称的文本颜色保持为绿色,其他所有颜色变为白色。

After @kostix suggestion, I searched the internet with proper key-words and found this question thread and then finally to this page . @kostix建议之后,我在互联网上搜索了适当的关键字,找到了该问题主题 ,然后最终转到了该页面 After trying approaches mentioned there, I ended up with the following code which works much better. 在尝试了上面提到的方法之后,我得到了下面的代码,效果更好。 Add these code in the .bashrc file present in Home folder. 将这些代码添加到Home文件夹中的.bashrc文件中。 Find it using ~/.bashrc/ command. 使用~/.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's terminal screenshot - Ubuntu的终端屏幕截图-

在此处输入图片说明

VS code's terminal screenshot - VS代码的终端屏幕截图-

在此处输入图片说明

You can update the code to alter color code(s) depending on your choice. 您可以根据自己的选择更新代码以更改颜色代码。

Git bash does nothing special there: it's just a port to Windows of a stock bash shell. Git bash在那里没有什么特别的功能:它只是股票bash外壳Windows的端口。

"The trick" (not) here is the tweaks applied to the startup script of bash to make it have that fancy dynamically generated prompt. 这里的“技巧”(不是)是对bash启动脚本进行的调整,以使其具有动态生成的精美提示。 These tweaks, again, call nothing special but plain Git commands. 同样,这些调整除了普通的Git命令外,没有什么特别的要求。

Now just please do your further research and apply the tweaks GfW does to your local bash setup. 现在,请做进一步的研究,并将GfW所做的调整应用于您的本地bash设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM