Dotfiles, utilities, and other apparatus.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
754 B

  1. #!/usr/bin/env perl
  2. =pod
  3. =head1 NAME
  4. dog - lump STDIN and arguments together.
  5. =head1 SYNOPSIS
  6. dog [ B<--chomp> ] [ I<argument> ] [ I<argument> ] [ I<...> ]
  7. =head1 DESCRIPTION
  8. Concatenate arguments, and/or standard input, to standard output.
  9. =over
  10. =item B<-c --chomp>
  11. Remove any newlines from standard input.
  12. If an argument is B<->, it will be replaced with standard input.
  13. =back
  14. =head1 EXAMPLES
  15. echo bar | dog -c foo - baz
  16. =head1 AUTHOR
  17. Brennen Bearnes
  18. =cut
  19. use strict;
  20. use warnings;
  21. use Getopt::Long;
  22. # chomp any trailing newline from STDIN?
  23. my $chomp = 0;
  24. GetOptions(chomp => \$chomp);
  25. for (@ARGV) {
  26. if ($_ eq '-') {
  27. while (<STDIN>) {
  28. chomp if (eof(STDIN) && $chomp);
  29. print;
  30. }
  31. } else {
  32. print;
  33. }
  34. }