Skip to content

Instantly share code, notes, and snippets.

@petdance
Created April 20, 2017 14:28
Show Gist options
  • Save petdance/7c44793015b58c110a75c7b75f4d49b6 to your computer and use it in GitHub Desktop.
Save petdance/7c44793015b58c110a75c7b75f4d49b6 to your computer and use it in GitHub Desktop.
dirty, a shell script for showing modified files whether under Git or Subversion.
#!/usr/bin/perl
use warnings;
use strict;
# Try Git.
my @lines = qx{git diff --name-only 2> /dev/null};
if ( $? == 0 ) {
print for @lines;
exit 0;
}
# Try Subversion.
@lines = qx/svn status 2>&1/;
exit if @lines == 0;
chomp @lines;
my $first = $lines[0];
if ( $first !~ /svn: warning: .+ not a working copy/ ) {
@lines = grep { !/^[?D]/ } @lines; # Ignore unversioned and deleted files
s/^........// for @lines;
print "$_\n" for @lines;
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment