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

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

问题描述

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

例如,他们有(类似的) :

pre $ mike @ treehouseMac:[/ Work / test - feature-branch-name] $ git add。
mike @ treehouseMac:[/ Work / test - 特性分支名称] $ git commit -m某些功能。
mike @ treehouseMac:[/ Work / test - feature-branch-name] $ git checkout master
mike @ treehouseMac:[/ Work / test - master] $ git status

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



我使用Mac OSX 10.8

解决方案

这不是关于插件。这是关于shell中的提示技巧。

对于bash中的一个很酷的设置,请查看这个人的 dotfiles 项目:



https://github.com/mathiasbynens/dotfiles



为了得到一个奇妙的提示,在〜/ .bash_profile 中包含 .bash_prompt 〜/ .bashrc



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

  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 * 来自这个回购的文件大约一个月前,这对我来说真的很有用。



对于Git,在 .gitconfig .osx 中还有更多的好东西。

/ p>

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?

I'm using Mac OSX 10.8

解决方案

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

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

https://github.com/mathiasbynens/dotfiles

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

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\]"

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

For Git, there are extra goodies in .gitconfig.

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

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

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