diff options
author | B. Watson <yalhcru@gmail.com> | 2015-04-08 01:09:31 -0400 |
---|---|---|
committer | B. Watson <yalhcru@gmail.com> | 2015-04-08 01:09:31 -0400 |
commit | 09e8113d7c05157cd54e16f820f6c7ce471d53b7 (patch) | |
tree | 3a481b2f6f13e827495e90e83c509204fa19582a /mkslackdesc | |
parent | c09112454417693693c265963b1f829695611b2d (diff) | |
download | sbostuff-09e8113d7c05157cd54e16f820f6c7ce471d53b7.tar.gz |
Add some more scripts
Diffstat (limited to 'mkslackdesc')
-rwxr-xr-x | mkslackdesc | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/mkslackdesc b/mkslackdesc new file mode 100755 index 0000000..4795a74 --- /dev/null +++ b/mkslackdesc @@ -0,0 +1,72 @@ +#!/usr/bin/perl -w + +# mkslackdesc + +# Convert a README into a valid slack-desc. + +# Usage: mkslackdesc [input] + +# If input not given, reads the file README in the current dir. +# To read from standard input, give - as the input file. + +# Output: a slack-desc, including the "how to edit" comments +# and the "handy ruler" line. If the input text won't fit into +# 11 72-characters lines, the output will not be a valid slack-desc, +# and you'll get a warning to that effect. + +# Output is to slack-desc in the current directory, and is also echoed +# to standard output. + +if(-e "slack-desc") { + die "slack-desc already exists in current directory!\n"; +} + +chomp ($pkg = `pwd`); +$pkg =~ s,.*/,,; + +if(!@ARGV) { + push @ARGV, "README"; +} + +open my $f, ">slack-desc" or die $!; +print "Writing to slack-desc:\n\n"; + +$ruler = <<EOF; +# HOW TO EDIT THIS FILE: +# The "handy ruler" below makes it easier to edit a package description. +# Line up the first '|' above the ':' following the base package name, and +# the '|' on the right side marks the last column you can put a character in. +# You must make exactly 11 lines for the formatting to be correct. It's also +# customary to leave one space after the ':' except on otherwise blank lines. + +EOF + +$ruler .= (' ' x length($pkg)) . <<EOF; +|-----handy-ruler------------------------------------------------------| +EOF + +print $ruler; +print $f $ruler; + +$lines = 11; +open my $pipe, "fmt -s -w 71 < $ARGV[0] |" or die $!; +while($_ = <$pipe>) { + --$lines; + chomp; + my $outline = "$pkg:"; + $outline .= " $_" if $_; + $outline .= "\n"; + print $outline; + print $f $outline; +} + +close $pipe; + +if($lines < 0) { + warn "slack-desc is too long (should be 11 lines), output not valid\n"; +} else { + print "$pkg:\n" for 1..$lines; + print $f "$pkg:\n" for 1..$lines; +} + +close $f; |