diff options
author | Mattias Andrée <maandree@operamail.com> | 2012-07-18 23:55:00 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2012-07-18 23:55:00 +0200 |
commit | b667e66071d4e3d52b1b52b33e745475444e7e2c (patch) | |
tree | 96d627483e6deb725607e40742c6fd8816526acd | |
parent | 4b9db7c37fe919ff0b6124213775a64a255ca53e (diff) | |
download | ponysay-b667e66071d4e3d52b1b52b33e745475444e7e2c.tar.gz ponysay-b667e66071d4e3d52b1b52b33e745475444e7e2c.tar.bz2 ponysay-b667e66071d4e3d52b1b52b33e745475444e7e2c.zip |
new options, ponysay -L, just like ponysay -l but puts symlinks inside brackets after their targets, I also edited Makefile to preserve symlinks
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | README | 6 | ||||
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | manuals/manpage.6 | 3 | ||||
-rwxr-xr-x | ponysay | 110 |
5 files changed, 114 insertions, 15 deletions
@@ -26,8 +26,8 @@ install: all mkdir -p "$(DESTDIR)/usr/share/ponysay/" mkdir -p "$(DESTDIR)/usr/share/ponysay/ponies" mkdir -p "$(DESTDIR)/usr/share/ponysay/ttyponies" - cp ponies/*.pony "$(DESTDIR)/usr/share/ponysay/ponies/" - cp ttyponies/*.pony "$(DESTDIR)/usr/share/ponysay/ttyponies/" + cp -P ponies/*.pony "$(DESTDIR)/usr/share/ponysay/ponies/" + cp -P ttyponies/*.pony "$(DESTDIR)/usr/share/ponysay/ttyponies/" mkdir -p "$(DESTDIR)/usr/bin/" install "ponysay" "$(DESTDIR)/usr/bin/ponysay" @@ -25,11 +25,11 @@ Required runtime dependencies 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 @@ -70,11 +70,11 @@ Dependencies `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 diff --git a/manuals/manpage.6 b/manuals/manpage.6 index f2a39a2..daa221e 100644 --- a/manuals/manpage.6 +++ b/manuals/manpage.6 @@ -51,6 +51,9 @@ Show version of program. .B \-l List pony files. .TP +.B \-L +List pony files with synonyms inside brackets. +.TP .B \-f \fIname\fP 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. @@ -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 |