Skip to content

Instantly share code, notes, and snippets.

@jedediah
Created September 6, 2009 22:23
Show Gist options
  • Save jedediah/182020 to your computer and use it in GitHub Desktop.
Save jedediah/182020 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
host = `hostname`.chomp
user = ENV['USER'] || '???'
pwd = Dir.pwd
term = ENV['TERM'] || ''
x = ''
x << "\e]0;#{pwd}\a" if term =~ /xterm|rxvt/ # set window title
x << "\e[1;36;44m #{user}@#{host} \e[1;33;44m#{pwd} "
git_status = `git status 2>/dev/null`
if $?.exitstatus < 128
git_branch = if git_status =~ /On branch (.*)/
$1
else
'???'
end
x << "\e[1;36;44mgit: \e[1;35;44m#{git_branch} "
changes = Hash.new {|h,k| h[k] = [] }
curtype = nil
git_status.lines.each do |line|
case line
when /Changes to be committed/
curtype = :staged
when /Changed but not updated/
curtype = :unstaged
when /(new file|modified|renamed|deleted):\s+(.*)/
changes[curtype] << $2
end
end
[[:staged,32],[:unstaged,31]].each do |t,c|
unless changes[t].empty?
s = changes[t].join ' '
s = "(#{changes[t].size} files)" if s.size > 30
x << "\e[1;#{c};44m#{s} "
end
end
end
x << "\e[00m"
puts x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment