Skip to content

Instantly share code, notes, and snippets.

@chyld
Last active March 22, 2018 03:29
Show Gist options
  • Save chyld/4644402 to your computer and use it in GitHub Desktop.
Save chyld/4644402 to your computer and use it in GitHub Desktop.
# encoding: utf-8
branches = STDIN.read.chomp
if !branches.empty?
branch = branches.split("\n").map(&:strip)[0].split(' ').map(&:strip)[-1]
second_line = branches.split("\n").map(&:strip)[1]
is_clean = second_line == "nothing to commit, working directory clean"
if !branches.empty?
if is_clean
puts " ✓ #{branch}"
else
puts "\e[0;31m ✗ #{branch}"
end
end
end
@khalua
Copy link

khalua commented Jan 30, 2013

if you change line 11 to

  puts "\e[0;31m" + " ✗ #{branch}"

it'll be red and more visible.

WORD

@gdomingu
Copy link

With git version 2.5.3. I had to modify this slightly to be

last_line = branches.split("\n").map(&:strip).last
is_clean = last_line == "nothing to commit, working directory clean"

@khalua
Copy link

khalua commented Mar 22, 2018

hey @gdomingu , thanks! I know this is 3 years late, but this little ruby script is awesome, and I was wondering why it stopped working :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment