aboutsummaryrefslogtreecommitdiff
path: root/ponysay
diff options
context:
space:
mode:
Diffstat (limited to 'ponysay')
-rwxr-xr-xponysay110
1 files changed, 103 insertions, 7 deletions
diff --git a/ponysay b/ponysay
index 3cffbdd..a08dc55 100755
--- a/ponysay
+++ b/ponysay
@@ -18,17 +18,111 @@ 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() {
- 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"
- 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
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
}
@@ -45,6 +139,7 @@ Options:
-v Show version and exit.
-h Show this help and exit.
-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.)
-W[column] The screen column where the message should be wrapped.
@@ -104,13 +199,14 @@ say() {
ponies=()
-while getopts f:W:lhv OPT
+while getopts f:W:Llhv OPT
do
case ${OPT} in
v) version; exit ;;
h) usage; exit ;;
f) ponies+=( "$OPTARG" ) ;;
l) list; exit ;;
+ L) linklist; exit ;;
W) wrap="$OPTARG" ;;
\?) usage >&2; exit 1 ;;
esac