djmitche (owner)

Fork Of

gist: 31631 by henrik Git branch and dirty state ...

Forks

Revisions

  • 6d57f3 djmitche Sun Feb 01 10:24:26 -0800 2009
  • b10d95 djmitche Thu Jan 15 09:35:03 -0800 2009
  • 10f9e8 djmitche Thu Jan 15 09:34:49 -0800 2009
  • f92050 djmitche Thu Jan 15 09:16:56 -0800 2009
  • 1be232 djmitche Thu Jan 15 09:15:45 -0800 2009
  • 42f928 henrik Wed Dec 03 10:00:32 -0800 2008
  • 4b35ab henrik Wed Dec 03 09:56:56 -0800 2008
gist: 47486 Download_button fork
public
Description:
edit existing PS1; be more efficient
Public Clone URL: git://gist.github.com/47486.git
Embed All Files: show embed
.bashrc #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir [master] $ # clean working directory
# username@Machine ~/dev/dir [master*] $ # dirty working directory
# djmitche: *edit* an existing PS1 to add the git information
# djmitche: only invoke 'git' and 'sed' once (each) for each prompt
# djmitche: display [NO BRANCH] when not on a branch (e.g., during rebase -i)
 
function __git_info {
  local status dirty branch
  status=$(git status 2> /dev/null)
  test -z "$status" && return
  [[ "$status" =~ "working directory clean" ]] || dirty="*"
  if [[ "$status" =~ "Not currently on any branch" ]]; then
    branch="NO BRANCH";
  else
    branch=$(sed '1{s/.*branch \(.*\).*/\1/g;q}' <<<"$status")
  fi
  echo " [$branch$dirty]"
}
# append git info to the current prompt
export PS1=`echo "$PS1"|sed 's/\\\\w/\\\\w$(__git_info)/g'`