new options, ponysay -L, just like ponysay -l but puts symlinks inside brackets after their targets, I also edited Makefile to preserve symlinks

This commit is contained in:
Mattias Andrée 2012-07-18 23:55:00 +02:00
parent 4b9db7c37f
commit b667e66071
5 changed files with 114 additions and 15 deletions

View file

@ -26,8 +26,8 @@ install: all
mkdir -p "$(DESTDIR)/usr/share/ponysay/" mkdir -p "$(DESTDIR)/usr/share/ponysay/"
mkdir -p "$(DESTDIR)/usr/share/ponysay/ponies" mkdir -p "$(DESTDIR)/usr/share/ponysay/ponies"
mkdir -p "$(DESTDIR)/usr/share/ponysay/ttyponies" mkdir -p "$(DESTDIR)/usr/share/ponysay/ttyponies"
cp ponies/*.pony "$(DESTDIR)/usr/share/ponysay/ponies/" cp -P ponies/*.pony "$(DESTDIR)/usr/share/ponysay/ponies/"
cp ttyponies/*.pony "$(DESTDIR)/usr/share/ponysay/ttyponies/" cp -P ttyponies/*.pony "$(DESTDIR)/usr/share/ponysay/ttyponies/"
mkdir -p "$(DESTDIR)/usr/bin/" mkdir -p "$(DESTDIR)/usr/bin/"
install "ponysay" "$(DESTDIR)/usr/bin/ponysay" install "ponysay" "$(DESTDIR)/usr/bin/ponysay"

6
README
View file

@ -25,11 +25,11 @@ 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, sort, head and tail coreutils : the main script [file: ponysay] uses stty, cut, ls, cat, sort, readlink, 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` and `ponysay -L`
perl : required to run ponysay -l perl : required to run `ponysay -l` and `ponysay -L`
Optional runtime dependencies Optional runtime dependencies

View file

@ -70,11 +70,11 @@ Dependencies
`cowsay`: this is a wrapper for cowsay `cowsay`: this is a wrapper for cowsay
`coreutils`: the main script uses stty, cut, ls, cat, sort, head and tail `coreutils`: the main script uses stty, cut, ls, cat, sort, readlink, 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` and `ponysay -l`
`perl`: required to run `ponysay -l` `perl`: required to run `ponysay -l` and `ponysay -L`
### Package building dependencies ### Package building dependencies

View file

@ -51,6 +51,9 @@ Show version of program.
.B \-l .B \-l
List pony files. List pony files.
.TP .TP
.B \-L
List pony files with synonyms inside brackets.
.TP
.B \-f \fIname\fP .B \-f \fIname\fP
Select a pony (either a file name or a pony name), you can use this options multiple times, Select a pony (either a file name or a pony name), you can use this options multiple times,
and one of the will be selected randomly. and one of the will be selected randomly.

110
ponysay
View file

@ -18,17 +18,111 @@ version() {
echo "ponysay v$version" echo "ponysay v$version"
} }
scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2`
listcmd=$(echo $0 | sed -e 's/\/ponysay$/\//g' -e 's/\/ponythink$/\//g')"ponysaylist.pl"
list() { list() {
scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2`
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"
perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed "s/.pony//" | sort) perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed -e 's/\.pony$//' | sort)
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"
perl $listcmd $scrw $(ls --color=no $HOMEPONIES | sed "s/.pony//" | sort) perl $listcmd $scrw $(ls --color=no $HOMEPONIES | sed -e 's/\.pony$//' | sort)
fi
}
_linklist() {
echo -e "\\e[01mponyfiles located in $1:\\e[21m"
files=$(ls --color=no $1 | sed -e 's/\.pony$//' | sort)
args=""
for file in $files; do
target=$(readlink $1"/"$file".pony")
if [[ $target = "" ]]; then
target=$file
else
target=$(echo $target | sed -e 's/^\.\///g' -e 's/\.pony$//g')
fi
args=$(echo $args $file $target)
done
scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2`
perl '/dev/stdin' $(echo $args) <<EOF | sed -e 's/ /_/g' > /dev/shm/ponysay~
#!/usr/bin/perl
#Author: Mattias Andrée (maandree@kth.se)
%hash = ();
\$argc = @ARGV;
\$i = 0;
while (\$i < \$argc)
{
\$source = \$ARGV[\$i];
\$i += 1;
\$target = \$ARGV[\$i];
\$i += 1;
if (\$source eq \$target)
{
\$hash{\$source} = [ () ];
}
}
\$i = 0;
while (\$i < \$argc)
{
\$source = \$ARGV[\$i];
\$i += 1;
\$target = \$ARGV[\$i];
\$i += 1;
unless (\$source eq \$target)
{
push @{ \$hash{\$target} }, \$source;
}
}
\$i = 0;
while (\$i < \$argc)
{
\$source = \$ARGV[\$i];
\$i += 1;
\$target = \$ARGV[\$i];
\$i += 1;
if (\$source eq \$target)
{
@list = @{ \$hash{\$source} };
\$first = 1;
print \$source;
foreach \$link (@list)
{
if (\$first eq 1)
{
print " (".\$link;
\$first = 0;
}
else
{
print " ".\$link;
}
}
if (\$first eq 0)
{
print ")";
}
print "\n";
}
}
EOF
perl $listcmd $scrw $(cat /dev/shm/ponysay~) | sed -e 's/_/ /g'
}
linklist() {
_linklist $SYSTEMPONIES
if [[ -d $HOMEPONIES ]]; then
_linklist $HOMEPONIES
fi fi
} }
@ -45,6 +139,7 @@ Options:
-v Show version and exit. -v Show version and exit.
-h Show this help and exit. -h Show this help and exit.
-l List pony files. -l List pony files.
-L List pony files with synonyms inside brackets.
-f[name] Select a pony (either a file name or a pony name.) -f[name] Select a pony (either a file name or a pony name.)
-W[column] The screen column where the message should be wrapped. -W[column] The screen column where the message should be wrapped.
@ -104,13 +199,14 @@ say() {
ponies=() ponies=()
while getopts f:W:lhv OPT while getopts f:W:Llhv OPT
do do
case ${OPT} in case ${OPT} in
v) version; exit ;; v) version; exit ;;
h) usage; exit ;; h) usage; exit ;;
f) ponies+=( "$OPTARG" ) ;; f) ponies+=( "$OPTARG" ) ;;
l) list; exit ;; l) list; exit ;;
L) linklist; exit ;;
W) wrap="$OPTARG" ;; W) wrap="$OPTARG" ;;
\?) usage >&2; exit 1 ;; \?) usage >&2; exit 1 ;;
esac esac