From b667e66071d4e3d52b1b52b33e745475444e7e2c Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 18 Jul 2012 23:55:00 +0200 Subject: new options, ponysay -L, just like ponysay -l but puts symlinks inside brackets after their targets, I also edited Makefile to preserve symlinks --- ponysay | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 103 insertions(+), 7 deletions(-) (limited to 'ponysay') 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) < /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 -- cgit