Last active
January 22, 2016 22:46
-
-
Save ollieatkinson/fc791a84edaed389ae86 to your computer and use it in GitHub Desktop.
PS1 - git dirty branch using a ruby script
This file contains hidden or 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
export PS1="\w \[\e[0;33m\]\`ruby ~/.theme/git.rb\` \[\e[0m\]\\$ " |
This file contains hidden or 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
def branch_status | |
branch = `git symbolic-ref --short -q HEAD 2> /dev/null` | |
rebase = rebase_branch | |
return " [#{branch.strip}#{dirty_status}]" if branch.to_s != '' | |
return " [#{rebase_branch}#{dirty_status}]" if rebase.to_s != '' | |
end | |
def rebase_branch | |
groups = `git status`.scan(/You are currently rebasing branch '(.*)' on '(.*)'/) | |
"rebasing #{groups[0][0]} on #{groups[0][1]}" unless groups.count == 0 | |
end | |
def dirty_status | |
mapping = { | |
'??' => '?', # untracked | |
'M' => '!', # modified | |
'D' => 'x', # deleted | |
'A' => '+', # new file | |
'R' => '>', # renamed | |
} | |
status = `git status --porcelain`.split("\n").map { |line| line[0..2].strip }.map do |key| | |
mapping[key] | |
end.uniq.join('') | |
" #{status}" if status.to_s != '' | |
end | |
puts branch_status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment