flewless ponysay -l

This commit is contained in:
Mattias Andrée 2012-07-18 19:39:04 +02:00
parent 494dbd1eb5
commit b5868da56c
5 changed files with 79 additions and 19 deletions

View file

@ -32,6 +32,7 @@ install: all
mkdir -p "$(DESTDIR)/usr/bin/" mkdir -p "$(DESTDIR)/usr/bin/"
install "ponysay" "$(DESTDIR)/usr/bin/ponysay" install "ponysay" "$(DESTDIR)/usr/bin/ponysay"
install -s "ponysaytruncater" "$(DESTDIR)/usr/bin/ponysaytruncater" install -s "ponysaytruncater" "$(DESTDIR)/usr/bin/ponysaytruncater"
install "ponysaylist.pl" "$(DESTDIR)/usr/bin/ponysaylist.pl"
ln -sf "ponysay" "$(DESTDIR)/usr/bin/ponythink" ln -sf "ponysay" "$(DESTDIR)/usr/bin/ponythink"
mkdir -p "$(DESTDIR)/usr/share/zsh/site-functions/" 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/ponies"
rm -fr "$(DESTDIR)/usr/share/ponysay/ttyponies" rm -fr "$(DESTDIR)/usr/share/ponysay/ttyponies"
unlink "$(DESTDIR)/usr/bin/ponysay" unlink "$(DESTDIR)/usr/bin/ponysay"
unlink "$(DESTDIR)/usr/bin/ponysaylist.pl"
unlink "$(DESTDIR)/usr/bin/ponysaytruncater" unlink "$(DESTDIR)/usr/bin/ponysaytruncater"
unlink "$(DESTDIR)/usr/bin/ponythink" unlink "$(DESTDIR)/usr/bin/ponythink"
unlink "$(DESTDIR)/usr/share/zsh/site-functions/_ponysay"; unlink "$(DESTDIR)/usr/share/zsh/site-functions/_ponysay";

4
README
View file

@ -25,10 +25,12 @@ Required runtime dependencies
cowsay : this is a wrapper for cowsay 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 sed : used to remove .pony from pony named when running ponysay -l
perl : required to run ponysay -l
Optional runtime dependencies Optional runtime dependencies
============================= =============================

View file

@ -70,10 +70,12 @@ Dependencies
`cowsay`: this is a wrapper for cowsay `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` `sed`: used to remove .pony from pony named when running `ponysay -l`
`perl`: required to run `ponysay -l`
### Package building dependencies ### Package building dependencies
`gcc`: used for compiling ponysaytruncater.c `gcc`: used for compiling ponysaytruncater.c

21
ponysay
View file

@ -20,28 +20,15 @@ version() {
list() { list() {
scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2` 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" echo -e "\\e[01mponyfiles located in $SYSTEMPONIES:\\e[21m"
files=`ls -1 $SYSTEMPONIES | sed "s/.pony//"` perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed "s/.pony//" | sort)
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
if [[ -d $HOMEPONIES ]]; then if [[ -d $HOMEPONIES ]]; then
echo -e "\\e[01mponyfiles located in $HOMEPONIES:\\e[21m" echo -e "\\e[01mponyfiles located in $HOMEPONIES:\\e[21m"
files=`ls -1 $HOMEPONIES | sed "s/.pony//"` perl $listcmd $scrw $(ls --color=no $HOMEPONIES | sed "s/.pony//" | sort)
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
fi fi
} }

67
ponysaylist.pl Executable file
View file

@ -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";
}