#!/usr/bin/perl -w
# Purpose:
# Wrapper to work around the coreutils issue of '-1' now being removed from
# 'head' and 'tail'
#
# Author:
# Robin H. Johnson <robbat2@gentoo.org>
#
# To install:
# OLDHEAD=`which head`
# OLDTAIL=`which tail`
# mv ${OLDHEAD} ${OLDHEAD}.bin
# mv ${OLDTAIL} ${OLDTAIL}.bin
# cp this-script.pl ${OLDHEAD}
# ln -s ${OLDHEAD} ${OLDTAIL}
# chmod +x ${OLDHEAD}
#
# Detailed description:
# (Just go and read the code, it's simple enough!)
#
# Disclaimer:
# You may do whatever you want with this script (including taking over the
# world).  However, I provide it 'as-is' with no warranty, and you cannot hold
# me responsible for any unwanted side effects.
# If you use it for something, I'd appreciate an email :-).

# be harsh...
use strict;
# As little as possible.
use File::Basename qw(basename);

# name of me
my $mename = basename($0);

# suffix to the real binary by my name
my $suffix = ".bin";

# what to call
my $realname = $mename.$suffix;

# marker to say we have hit dashdash
my $hitdashdash = 0;

# Run over the array
for(my $i=0;$i < @ARGV;$i++) {
	# Keep an eye out for '--'
	if($ARGV[$i] eq '--') {
		$hitdashdash = 1;
	}
	# if we haven't hit a '--' and the argument is '-1', then fix it!
	if(!$hitdashdash and ($ARGV[$i] eq '-1')) {
		$ARGV[$i] = '-n1';
	}
}

# Launch it now
exec $realname, @ARGV;

# vim: ts=4 sts=4 sw=4 noexpandtab:
