-
-
Save mtanzi/5658683 to your computer and use it in GitHub Desktop.
Pesonalized KieranP's work at https://gist.github.com/KieranP/92895
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NO_COLOR='\e[0m' #disable any colors | |
BLACK='\e[0;30m' | |
RED='\e[0;31m' | |
GREEN='\e[0;32m' | |
YELLOW='\e[0;33m' | |
BLUE='\e[0;34m' | |
MAGENTA='\e[0;35m' | |
CYAN='\e[0;36m' | |
WHITE='\e[0;37m' | |
parse_git_branch_and_status() { | |
ruby ~/.git-prompt.rb | |
} | |
export PS1="\[$PS_COLOR\]\u:\[$GREEN\]\w \$(parse_git_branch_and_status)\[$YELLOW\]\n\$\[$NO_COLOR\] " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class GitConsoleStats | |
COLORS = { | |
black: "\033[0;30m", | |
red: "\033[0;31m", | |
green: "\033[0;32m", | |
yellow: "\033[0;33m", | |
blue: "\033[0;34m", | |
magenta: "\033[0;35m", | |
cyan: "\033[0;36m", | |
white: "\033[0;37m" | |
} | |
@@default_color = COLORS[:green] | |
@@user_color = COLORS[:cyan] | |
@@branch_color = COLORS[:yellow] | |
@@modified_color = COLORS[:red] | |
@@not_modified_color = COLORS[:green] | |
def print | |
return if git_status.nil? || git_status.empty? || git_status.include?('fatal') | |
info = Array.new | |
info << "#{untracked_files_count} untracked" if untracked_files_count > 0 | |
info << "#{new_files_count} new" if new_files_count > 0 | |
info << "#{modified_files_count} modified" if modified_files_count > 0 | |
info << "#{deleted_files_count} deleted" if deleted_files_count > 0 | |
info << "#{renamed_files_count} renamed" if renamed_files_count > 0 | |
info << "#{copied_files_count} copied" if copied_files_count > 0 | |
info << "#{merge_conflicts_count} merge conflict#{'s' if merge_conflicts_count > 1}" if merge_conflicts_count > 0 | |
modified_info = "#{@@modified_color}#{info.join(', ')} " if info.size > 0 | |
puts "#{@@branch_color}(#{branch_name})#{@@default_color} #{modified_info}" | |
end | |
def git_status | |
@@git_status ||= `git status -sb 2>/dev/null` | |
end | |
def branch_name | |
@@branch_name ||= git_status =~ /^##\s([^\[$\n]*)/ ? $1.strip.split('...').first : '[unknown branch]' | |
end | |
def untracked_files_count | |
@@untracked_files_count ||= git_status.scan(/^\?\?/).size | |
end | |
def new_files_count | |
@@new_files_count ||= git_status.scan(/^(A|\s)(A|\s)/).size | |
end | |
def modified_files_count | |
@@modified_files_count ||= git_status.scan(/^(M|\s)(M|\s)/).size | |
end | |
def deleted_files_count | |
@@deleted_files_count ||= git_status.scan(/^(D|\s)(D|\s)/).size | |
end | |
def renamed_files_count | |
@@renamed_files_count ||= git_status.scan(/^(R|\s)(R|\s)/).size | |
end | |
def copied_files_count | |
@@copied_files_count ||= git_status.scan(/^(C|\s)(C|\s)/).size | |
end | |
def merge_conflicts_count | |
@@merge_conflicts_count ||= git_status.scan(/^(D|U|T|\s)(D|U|T|\s)/).size | |
end | |
end | |
GitConsoleStats.new.print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment