[英]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 - 我已经检查了以下链接的答案-
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.