Skip to content

Instantly share code, notes, and snippets.

@ollieatkinson
Last active January 22, 2016 22:46
Show Gist options
  • Save ollieatkinson/fc791a84edaed389ae86 to your computer and use it in GitHub Desktop.
Save ollieatkinson/fc791a84edaed389ae86 to your computer and use it in GitHub Desktop.
PS1 - git dirty branch using a ruby script
export PS1="\w \[\e[0;33m\]\`ruby ~/.theme/git.rb\` \[\e[0m\]\\$ "
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