5 ms·
Git info in your ZSH Prompt
- aditya 16y agoI've been really digging oh-my-zsh recently for extending zsh, comes with a great plugin architecture and all sorts of cool shit: http://github.com/robbyrussell/oh-my-zsh http://github.com/robbyrussell/oh-my-zsh
- sudonim 16y agoBeat me to the punch... Oh-my-zsh ftw. Robby Russell has a great blog about rails development too. http://www.robbyonrails.com/ http://www.robbyonrails.com/
- silentbicycle 16y agoWow, am I the only person who prefers a shell prompt of just "$ "? I have a bunch of abbreviations for common git commands, though, so I guess it balances out.
- elbenshira 16y agoI like knowing what branch I'm in without having to do a "git br".
- sjs 16y agoYou just might be. ;-) I have git status in my prompt but also use short shell aliases. If anyone's curious: http://github.com/samsonjs/config/blob/master/zsh/zshrc#L230-262 http://github.com/samsonjs/config/blob/master/zsh/zshrc#L230...
- krakensden 16y agoYou're not- I can't stand waiting 3-5 seconds every time I hit enter, just so I can have a more verbose prompt that tells me things I already knew.
- paulbaumgart 16y agoThe one I wrote, for Bash, uses SIGALRM (via the Time::HiRes perl module) to time out after half a second: http://github.com/paulbaumgart/git-situational-awareness http://github.com/paulbaumgart/git-situational-awareness
- bostonvaulter2 16y agoIt would be cool to do the opposite as well, don't start checking the fancy vcs stuff until 1/2 second after the prompt is loaded.
- paulbaumgart 16y agoAgreed. I don't think Bash allows async function execution, though.
- silentbicycle 16y agoIt seems a lot simpler to just type "git br" (or, heck, "gb") when I care. Usually I have a good reason for being in a particular branch, though I tend to check before doing merging anyway. When I want to fiddle with minor configuration details, hey, bash and zsh users have nothing on emacs. ;)
- Jach 16y agoThis seems to be a large difference in people's work flows. Some of us like to remember things like what branch we're in, the file system structure of our project so we can edit in vim without needing NERDtree or some other IDE that organizes stuff, we like to know our libraries so we don't need auto-completion, and then there's the opposite people. For myself, I think the remember-for-me tools have their place, and I'm a fan of Flex's Flash Builder IDE even though I use vim for everything else, so I won't begrudge someone for choosing not to remember something. That's what doc is for. On the other hand, in this case I frequently just use 'git status' which reports my branch anyway among other info I want to double-check just in case I somehow forgot, and this is really just a neat shell trick rather than being really useful, like the one that prints a green ':)' when the last command succeeded and a red ':(' when it failed...
- lallysingh 16y agoI like a timestamp so that I know: (1) How long the last command took (approx, as there's time between the prompt showing and me putting in a command) (2) How long ago I ran the last command in a given shell window
- silentbicycle 16y agoWhen I care about the former (and I often do), I just prefix it with time. "time make bench" etc. The real / user / system break down is more meaningful than just wall clock time.
- compay 16y agoNope, me too. I can see maybe using a prompt like this temporarily, or putting this info in an XTerm's title, but I spend most of my time on the command line and really don't want crap like this distracting me. My prompt on localhost is always "$ " or "# ", but I add user and host on remote machines to avoid making any big mistakes on the servers I manage.
- silentbicycle 16y agoCome to think of it, I do actually keep that info around, I just put it in the status line* in tmux or dwm, rather than cluttering my shell prompt with it. I guess that's a different post, though! * Mine currently says: 3.1 pra | 0:ksh 1:top 2:ksh 4:ksh- 5:w3m* | . 1.45, 1.57, 1.01 . 2010-10-07 23:07 which has system load, time, battery (on laptops), etc. "pra" = "pranaferox", my desktop. (I usually have a lot more shells open than that, but I turned everything off while installing a new light in the ceiling earlier.)
- elbenshira 16y agoThere are a ton of these out there nowadays. A lot of them are OK, but I use: http://github.com/olivierverdier/zsh-git-prompt http://github.com/olivierverdier/zsh-git-prompt
- bostonvaulter2 16y agoI was just about to post that. I actually made a few patches (pulled by olivier) to make the prompt work better on Mac OSX.
- l0stman 16y agoNote also that there's a more feature complete version that accomplishes the same tasks in the contrib directory of git (http://git.kernel.org/?p=git/git.git;a=blob;f=contrib/completion/git-completion.bash;h=f83f019ca91a2611f5bd3474ccf6d10081320c4c;hb=HEAD http://git.kernel.org/?p=git/git.git;a=blob;f=contrib/comple...). It's implemented in bash but I use it with almost no modification with the Korn shell.
- avar 16y agoYou linked to the wrong version, given the topic of this thread. Recently ZSH support has been added to git-completion.bash, but it's still only in the "next" branch of git: http://git.kernel.org/?p=git/git.git;a=blob_plain;f=contrib/completion/git-completion.bash;hb=next http://git.kernel.org/?p=git/git.git;a=blob_plain;f=contrib/...
- KingOfB 16y agoThis makes me very happy, thanks!
- kevincolyar 16y agoI've started using the oh-my-zsh project. http://github.com/robbyrussell/oh-my-zsh http://github.com/robbyrussell/oh-my-zsh Has all sorts of themes, and most have git status.
- avar 16y agoYou can also use Git's own __git_ps1 from git-completion.bash in either bash or in zsh (see my other comment). Here's an example of it in use: http://github.com/avar/dotfiles/blob/master/.bashrc#L86 http://github.com/avar/dotfiles/blob/master/.bashrc#L86 It doesn't give you info about whether you have staged files (but maybe it should). But it gives you a bunch of other neat stuff, like whether you're in a git-rebase or git-am operation
- gruseom 16y agoIt definitely can tell you whether you have staged files, because I use it for that among other things. I don't remember how I turned that feature on, but it wasn't hard. Perhaps someone will chime in with the details.
- l0stman 16y agoJust add the following lines in your .bashrc: export GIT_PS1_SHOWDIRTYSTATE=yes export GIT_PS1_SHOWUNTRACKEDFILES=yes
- avar 16y agoThanks. I didn't know about those. I've configured them in my ~/.bashrc now: http://github.com/avar/dotfiles/commit/43454870 http://github.com/avar/dotfiles/commit/43454870
- kree10 16y agoI love that vcs_info works with more than just git. Having my prompt tell me what VCS I'm under (even knowing the difference between git and git-svn) and what branch I've got checked out helps me mentally switch gears as soon as I cd into a directory.