Skip to content

Instantly share code, notes, and snippets.

@jimmynguyc
Last active December 15, 2015 20:19
Show Gist options
  • Save jimmynguyc/5317442 to your computer and use it in GitHub Desktop.
Save jimmynguyc/5317442 to your computer and use it in GitHub Desktop.

Pretty prompt

Add this into ~/.bash_profile

parse_git_dirty() {
  [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo -en ""  
}
parse_git_info() {
   git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/ (\1)$(parse_git_dirty)/" 
}
parse_svn_dirty(){
  SVN_STATUS="`svn status 2> /dev/null`"
  
  if [ -z "$SVN_STATUS" ]
  then
    echo ''
  else
    DIRTY=false
    for i in $SVN_STATUS; do
      if [ '?' = "${i:0:1}" -o "M" == "${i:0:1}" -o "A" == "${i:0:1}" ]; then
        DIRTY=true
      fi
    done
    
    if [ $DIRTY == true ]; then
      echo -en ""  
    fi
    
  fi
}
parse_svn_info() {
  svn info 2> /dev/null | sed -n '6,6p' | awk '{print "Rev:"$2}' | sed -e "s/\(.*\)/ (\1)$(parse_svn_dirty)/" 
}

# color code
# \[\e[36m\]  (code here)   \[\e[0m\]
PS1="\u:\[\e[1m\]\W\[\e[0m\]\[\e[36m\]\$(parse_git_info)\[\e[0m\]\[\e[36m\]\$(parse_svn_info)\[\e[0m\] \[\e[31m\]〆\[\e[0m\]"

Git Shorthand & Aliases

Add this into ~/.gitconfig

[alias]
   co = checkout
   ci = commit
   st = status
   br = branch
   type = cat-file -t
   dump = cat-file -p
   lg1 = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(black)%s%C(reset) %C(black)- %an%C(reset)%C(bold red)%d%C(reset)' --abbrev-commit --date=relative
   lg2 = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold red)%d%C(reset)%n''          %C(white)%s%C(reset) %C(bold black)- %an%C(reset)' --abbrev-commit
   lg = !"git lg1"
   hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
   longhist = log --pretty=format:\"%H %ad | %s%d [%an]\" --graph --date=short
   # the hist alias messes up TextMate's syntax highlighting, which is why it is the last line.

This will give you the following git shorthand :-

  • git co = git checkout
  • git ci = git commit
  • git st = git status
  • git br = git branch
  • git type = git cat-file -t
  • git dump = git cat-file -p
  • git lg = pretty log format #1
  • git lg1 = pretty log format #2
  • git lg2 = pretty log format #3
  • git hist = pretty log format #4
  • git longhist = pretty log format #5

Git Autocomplete

brew install bash-completion

Follow the instructions and add the following to ~/.bash_profile

if [ -f `brew --prefix`/etc/bash_completion ]; then
    . `brew --prefix`/etc/bash_completion
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment