diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README | 4 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rwxr-xr-x | ponysay | 21 | ||||
-rwxr-xr-x | ponysaylist.pl | 67 |
5 files changed, 79 insertions, 19 deletions
@@ -32,6 +32,7 @@ install: all mkdir -p "$(DESTDIR)/usr/bin/" install "ponysay" "$(DESTDIR)/usr/bin/ponysay" install -s "ponysaytruncater" "$(DESTDIR)/usr/bin/ponysaytruncater" + install "ponysaylist.pl" "$(DESTDIR)/usr/bin/ponysaylist.pl" ln -sf "ponysay" "$(DESTDIR)/usr/bin/ponythink" mkdir -p "$(DESTDIR)/usr/share/zsh/site-functions/" @@ -74,6 +75,7 @@ uninstall: rm -fr "$(DESTDIR)/usr/share/ponysay/ponies" rm -fr "$(DESTDIR)/usr/share/ponysay/ttyponies" unlink "$(DESTDIR)/usr/bin/ponysay" + unlink "$(DESTDIR)/usr/bin/ponysaylist.pl" unlink "$(DESTDIR)/usr/bin/ponysaytruncater" unlink "$(DESTDIR)/usr/bin/ponythink" unlink "$(DESTDIR)/usr/share/zsh/site-functions/_ponysay"; @@ -25,10 +25,12 @@ Required runtime dependencies cowsay : this is a wrapper for cowsay - coreutils : the main script [file: ponysay] uses stty, cut, ls, cat, head and tail + coreutils : the main script [file: ponysay] uses stty, cut, ls, cat, sort, head and tail sed : used to remove .pony from pony named when running ponysay -l + perl : required to run ponysay -l + Optional runtime dependencies ============================= @@ -70,10 +70,12 @@ Dependencies `cowsay`: this is a wrapper for cowsay -`coreutils`: the main script uses stty, cut, ls, cat, head and tail +`coreutils`: the main script uses stty, cut, ls, cat, sort, head and tail `sed`: used to remove .pony from pony named when running `ponysay -l` +`perl`: required to run `ponysay -l` + ### Package building dependencies `gcc`: used for compiling ponysaytruncater.c @@ -20,28 +20,15 @@ version() { list() { scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2` - (( $scrw > 80 )) && scrw=80 + + listcmd=$(echo $0 | sed -e 's/\/ponysay$/\//g' -e 's/\/ponythink$/\//g')"ponysaylist.pl" echo -e "\\e[01mponyfiles located in $SYSTEMPONIES:\\e[21m" - files=`ls -1 $SYSTEMPONIES | sed "s/.pony//"` - maxw=1 - for file in $files; do - w=$(( `echo $file | wc -m` + 2 )) - (( $maxw < $w )) && maxw=$w - done - cols=$(( $scrw / $maxw )) - echo "$files" | pr -T --columns=$cols + perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed "s/.pony//" | sort) if [[ -d $HOMEPONIES ]]; then echo -e "\\e[01mponyfiles located in $HOMEPONIES:\\e[21m" - files=`ls -1 $HOMEPONIES | sed "s/.pony//"` - maxw=1 - for file in $files; do - w=$(( `echo $file | wc -m` )) - (( $maxw < $w )) && maxw=$w - done - cols=$(( $scrw / $maxw )) - echo "$files" | pr -T --columns=$cols + perl $listcmd $scrw $(ls --color=no $HOMEPONIES | sed "s/.pony//" | sort) fi } diff --git a/ponysaylist.pl b/ponysaylist.pl new file mode 100755 index 0000000..7a09376 --- /dev/null +++ b/ponysaylist.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl + +# ponysaylist +# Prints a list of ponies in columns +# +# Licensed under WTFPL +# See COPYING for details + +# Author: Mattias Andrée, maandree@kth.se + + +$first = 1; +$scrw = 1; +$maxw = 1; + +foreach $arg (@ARGV) +{ + if ($first == 1) + { $first = 0; + $scrw = $arg; + } + else + { $w = length $arg; + $maxw = $w if ($w > $maxw); + } +} + +$cols = int (($scrw + 2) / ($maxw + 2)); +$cols = 1 if ($cols < 1); + + +@list = (); + +$first = 1; +$items = 0; +foreach $arg (@ARGV) +{ + if ($first == 1) + { $first = 0; + } + else + { $ws = $maxw - (length $arg); + push @list, $arg.(" "x$ws); + $items += 1; + } +} + + +$rows = int (($items + $cols - 1) / $cols); +$i = 0; +@rowlist = (); + +while ($i < $items) +{ $row = 0; + while (($row < $rows) and ($i < $items)) + { + $rowlist[$row] .= " " unless ($i < $rows); + $rowlist[$row] .= $list[$i]; + $row += 1; + $i += 1; +} } + +foreach $row (@rowlist) +{ + print $row."\n"; +} + |