如何在终端中显示当前分支和文件夹路径? [英] How can I display the current branch and folder path in terminal?

查看:9
本文介绍了如何在终端中显示当前分支和文件夹路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在观看 Team Treehouse 的一些视频,他们在使用 Git 时有一个非常漂亮的终端.

I've been watching some of the Team Treehouse videos and they have a very nice looking terminal when working with Git.

例如他们有(类似的东西):

For example they have (something similar):

mike@treehouseMac: [/Work/test - feature-branch-name] $ git add .
mike@treehouseMac: [/Work/test - feature-branch-name] $ git commit -m "Some feature."
mike@treehouseMac: [/Work/test - feature-branch-name] $ git checkout master
mike@treehouseMac: [/Work/test - master] $ git status

我的终端如何向我显示我所在分支的一些有用信息,并用颜色来区分我想要的数据位?是否有某种事实上的插件我还没有找到?

How can my terminal show me some useful information of what branch I'm on, with colors to distinguish bits of the data I want? Is there some sort of de-facto plugin I haven't found yet?

我使用的是 Mac OSX 10.8

I'm using Mac OSX 10.8

推荐答案

这与插件无关.这是关于 shell 中的提示技巧.

It's not about a plugin. It's about prompt tricks in the shell.

要在 bash 中进行很酷的设置,请查看此人的 dotfiles 项目:

For a cool setup in bash, check out the dotfiles project of this guy:

https://github.com/mathiasbynens/dotfiles

要获得漂亮的提示,请在 ~/.bash_profile~/.bashrc 中包含 .bash_prompt.

To get a fancy prompt, include the .bash_prompt in your ~/.bash_profile or ~/.bashrc.

要获得与您的问题完全相同的提示,请像这样更改 .bash_prompt 末尾的 export PS1 行:

To get the exact same prompt as in your question, change the export PS1 line at the end of .bash_prompt like this:

export PS1="[${BOLD}${MAGENTA}]u[$WHITE]@[$ORANGE]h[$WHITE]: [[$GREEN]w[$WHITE]$([[ -n $(git branch 2> /dev/null) ]] && echo " - ")[$PURPLE]$(parse_git_branch)[$WHITE]] $ [$RESET]"

大约一个月前,我最终使用了此存储库中的所有 .bash* 文件,这对我来说非常有用.

I ended up using all the .bash* files from this repository about a month ago, and it's been really useful for me.

对于 Git,.gitconfig 中有额外的好处.

For Git, there are extra goodies in .gitconfig.

而且由于您是 mac 用户,.osx 中还有更多好东西.

And since you're a mac user, there are even more goodies in .osx.

这篇关于如何在终端中显示当前分支和文件夹路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆