Guest User

Untitled

a guest
Aug 19th, 2012
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # -*- coding: utf-8 -*-
  3.  
  4. # Emits Git metadata for use in a Zsh prompt.
  5. #
  6. # AUTHOR:
  7. # Ben Hoskings
  8. # https://github.com/benhoskings/dot-files/blob/master/files/bin/git_cwd_info
  9. #
  10. # MODIFIED:
  11. # Geoffrey Grosenbach http://peepcode.com
  12.  
  13. # The methods that get called more than once are memoized.
  14.  
  15. def git_repo_path
  16. @git_repo_path ||= `git rev-parse --git-dir 2>/dev/null`.strip
  17. end
  18.  
  19. def in_git_repo
  20. !git_repo_path.empty? &&
  21. git_repo_path != '~' &&
  22. git_repo_path != "#{ENV['HOME']}/.git"
  23. end
  24.  
  25. def git_parse_branch
  26. @git_parse_branch ||= `git-current-branch`.chomp
  27. end
  28.  
  29. def git_head_commit_id
  30. `git rev-parse --short HEAD 2>/dev/null`.strip
  31. end
  32.  
  33. def git_cwd_dirty
  34. " %{\e[90m%}✗%{\e[0m%}" unless git_repo_path == '.' || `git ls-files -m`.strip.empty?
  35. end
  36.  
  37. def rebasing_etc
  38. if File.exists?(File.join(git_repo_path, 'BISECT_LOG'))
  39. "+bisect"
  40. elsif File.exists?(File.join(git_repo_path, 'MERGE_HEAD'))
  41. "+merge"
  42. elsif %w[rebase rebase-apply rebase-merge ../.dotest].any? {|d| File.exists?(File.join(git_repo_path, d)) }
  43. "+rebase"
  44. end
  45. end
  46.  
  47. if in_git_repo
  48. print " %{\e[90m%}#{git_parse_branch} %{\e[37m%}#{git_head_commit_id}%{\e[0m%}#{rebasing_etc}#{git_cwd_dirty}"
  49. end
Advertisement
Add Comment
Please, Sign In to add comment