Skip to content

Instantly share code, notes, and snippets.

@dotsara
Last active December 20, 2015 23:49
Show Gist options
  • Save dotsara/6215093 to your computer and use it in GitHub Desktop.
Save dotsara/6215093 to your computer and use it in GitHub Desktop.

Ages and ages ago, coworkers provided me a custom shell prompt that would show me gemsets and branches. Awesome! Downside: my non-git directory prompts are super plain and nothing but $. Zzzzz

After working through gitimmersion.com and fiddling with git log output (colors!), it's time to revist my prompt.

Old prompt: export PS1='$(__git_ps1 "[\t] \h:\W $(~/.rvm/bin/rvm-prompt i g) (%s) ")$ '

  • git directory: [17:48:02] grintgotts:appdirectory gemset (branch) $
  • non-git directory: $

(Yes, my machine is called Gringotts. It's a place for keeping lots of things safe, yes?)

New prompt:

export PS1='\033[35m\][\t]\033[0m\] \h:\W\
[\033[32m\] $(__git_ps1 "$(~/.rvm/bin/rvm-prompt i g) \033[36m\](%s)\[\033[0m\] ")\[\033[0m\]$ '
  • (mind the line break just after the host:directory)
  • git directory: [17:48:02] gringotts:appdirectory gemset (branch) $ (time, purple; gemset, green; branch, cyan)
  • non-git directory: [17:48:02] gringotts:directory $ (time, purple)

How I got to the new prompt… Lots and lots of searching that only showed me git-specific stuff, leaving non-git super-boring. Then I found this post about using git and tried his prompt wholesale to see what would happen inside and out of git. Eureka! Finally, time and host:directory regardless of git.

And then I started playing. With this Bash prompt HOWTO about Colors, I figured out \033 resets color and the [##m\] sets a new color. And lo! my new prompt. (:

gitimmersion.com

From Jim Weirich!

  • Lab 6, staging changes Ah, so git reset HEAD <file> doesn't undo the changes you made to the file, it reverses your git add. Derp.
  • Lab 10, history Oooh, lots of options for git log; awesome! I like this, so far: git log --all --pretty=format:'%H %cd | %s (%an)' --date=short
  • Lab 28-30, resolving conflicts: phew, the --graph flag is definitely useful and I understand better, now, the point of merging master (into your branch) on the regular, but that graph can get confusing (and I've just done this work; trying to make sense of a messy graph on a branch I didn't create makes me nervous). Full history at the end of Lab 30.
  • Lab 32, resetting the greet branch Ooohh, "…looking at the data we see that the 'Updated Rakefile' commit was the last commit on the greet branch before merging." So, looking at the full history, the asterisks are the master branch, the pipes are the greet branch. Eeeenteresting. All right.
[09:16:12] gringotts:hello ree (greet) $ fullhist
* 673d36e 2013-08-13 | (HEAD, greet) Merged master fixed conflict.
|\
| * 273976c 2013-08-13 | (master) Made interactive
* | f6706df 2013-08-13 | Merge branch 'master' into greet
|\ \
| |/
| * 4012833 2013-08-13 | Added README
* | 0274c87 2013-08-13 | Updated Rakefile
* | f970c62 2013-08-13 | Hello uses Greeter
* | 2c756a1 2013-08-13 | Added greeter class
|/
* cd1cff0 2013-08-12 | Added a Rakefile.
* 36723c2 2013-08-12 | Moved hello.rb to lib
* 0985d1f 2013-08-12 | Add an author/email comment
* b44add4 2013-08-12 | (v1) Added a comment.
* 61658cb 2013-08-12 | (v1-beta) Added a default value
* c6f8e21 2013-08-12 | Using ARGV.
* f41527b 2013-08-12 | First commit
@dotsara
Copy link
Author

dotsara commented Aug 13, 2013

While I work through gitimmersion, I'm fiddling with my bash profile to try out different settings. At Lab 40, I'm mostly fiddling around with git log. I want to color certain items (hash, tags, branches), but I don't like that I'm stuck with red, green, and blue. Zzzz

At Git Config Hacks, I see that if you put a color in parentheses, you can do what you want! %C(bold blue) or in my case %C(yellow)

Using Jim's preferred log format, I tarted it up a little with some colors so the important(-to-me) bits jump out:
git log --pretty=format:'%C(yellow)%h %Creset%ad | %s%C(cyan)%d %Creset[%an]' --graph --date=short

Truly, it's the little things. (:

@dotsara
Copy link
Author

dotsara commented Oct 10, 2013

git difftool opens FileMerge for comparing git diff awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment