aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2012-07-18 19:39:04 +0200
committerMattias Andrée <maandree@operamail.com>2012-07-18 19:39:04 +0200
commitb5868da56c55ff0ce051b328f45470c8b0653ca4 (patch)
treed5f64922ae4f7c085fd878d793609ae24db540c2
parent494dbd1eb5a2ab9ebaa323d34061722fee3986af (diff)
downloadponysay-b5868da56c55ff0ce051b328f45470c8b0653ca4.tar.gz
ponysay-b5868da56c55ff0ce051b328f45470c8b0653ca4.tar.bz2
ponysay-b5868da56c55ff0ce051b328f45470c8b0653ca4.zip
flewless `ponysay -l`
-rw-r--r--Makefile2
-rw-r--r--README4
-rw-r--r--README.md4
-rwxr-xr-xponysay21
-rwxr-xr-xponysaylist.pl67
5 files changed, 79 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index cf34e18..84303de 100644
--- a/Makefile
+++ b/Makefile
@@ -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";
diff --git a/README b/README
index 8a7fb6f..7e65592 100644
--- a/README
+++ b/README
@@ -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
=============================
diff --git a/README.md b/README.md
index b117588..252c8ed 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/ponysay b/ponysay
index a5edea0..0928737 100755
--- a/ponysay
+++ b/ponysay
@@ -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";
+}
+