From 492b62f39e5a798a2253f2b39345313fb58ebae6 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 20 Jul 2012 04:55:29 +0200 Subject: m + work in info manual --- ponysay | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ponysay') diff --git a/ponysay b/ponysay index bacf1eb..de1aa09 100755 --- a/ponysay +++ b/ponysay @@ -67,7 +67,7 @@ _linklist() { scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2` - perl '/dev/stdin' $(echo $args) < /dev/shm/ponysay~ + perl '/dev/stdin' $(echo $args) < /dev/shm/.ponysay~ #!/usr/bin/perl #Author: Mattias Andrée (maandree@kth.se) @@ -134,7 +134,7 @@ while (\$i < \$argc) } EOF - perl $listcmd $scrw $(cat /dev/shm/ponysay~) | sed -e 's/_/ /g' | qlist + perl $listcmd $scrw $(cat /dev/shm/.ponysay~) | sed -e 's/_/ /g' | qlist } linklist() { -- cgit From 301197ff740addf34ad866cfbc532ad9a205e0bd Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 20 Jul 2012 05:10:41 +0200 Subject: new environment variable, PONYSAY_COWSAY, allows replace cowsay with another program, if this variable has a value the "use uft8" patch will not be applies --- ponysay | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'ponysay') diff --git a/ponysay b/ponysay index de1aa09..2d2a321 100755 --- a/ponysay +++ b/ponysay @@ -12,7 +12,13 @@ if [ "$TERM" = "linux" ]; then HOMEPONIES="${HOME}/.local/share/ponysay/ttyponies" fi -cmd=cowsay +if [[ "$PONYSAY_COWSAY" = "" ]]; then + cmd=cowsay + customcmd=0 +else + cmd="$PONYSAY_COWSAY" + customcmd=1 +fi [[ ${0} == *ponythink ]] && cmd=cowthink version() { @@ -208,14 +214,28 @@ say() { tail --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES )) } + if [[ $customcmd = 0 ]]; then + function cowcmd + { + pcmd='#!/usr/bin/perl\nuse utf8;' + ccmd=$(for c in $(echo $PATH":" | sed -e 's/:/\/'"$cmd"' /g'); do if [[ -f $c ]]; then echo $c; break; fi done) + perl <(cat <(echo -e $pcmd) $ccmd) "$@" + } + else + function cowcmd + { + $cmd "$@" + } + fi + if [ "$TERM" = "linux" ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'yes' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'y' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = '1' ]; then if [ "$PONYSAY_BOTTOM" = 'yes' ] || [ "$PONYSAY_BOTTOM" = 'y' ] || [ "$PONYSAY_BOTTOM" = '1' ]; then - perl <(cat <(echo -e '#!/usr/bin/perl\nuse utf8;') $(for c in $(echo $PATH":" | sed -e 's/:/\/'"$cmd"' /g'); do if [[ -f $c ]]; then echo $c; break; fi done)) -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunctail + cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunctail else - perl <(cat <(echo -e '#!/usr/bin/perl\nuse utf8;') $(for c in $(echo $PATH":" | sed -e 's/:/\/'"$cmd"' /g'); do if [[ -f $c ]]; then echo $c; break; fi done)) -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunchead + cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunchead fi else - perl <(cat <(echo -e '#!/usr/bin/perl\nuse utf8;') $(for c in $(echo $PATH":" | sed -e 's/:/\/'"$cmd"' /g'); do if [[ -f $c ]]; then echo $c; break; fi done)) -f "$pony" "${wrap:+-W$wrap}" | wtrunc + cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc fi } -- cgit From 122f1da602b9039c1f3dc958f5e1a355a6daf44a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 20 Jul 2012 05:22:46 +0200 Subject: fix on env var --- ponysay | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ponysay') diff --git a/ponysay b/ponysay index 2d2a321..04ab745 100755 --- a/ponysay +++ b/ponysay @@ -194,7 +194,7 @@ say() { function wtrunc { - if [ "$PONYSAY_FULL_WIDTH" = 'no' ] || [ "$PONYSAY_FULL_WIDTH" = 'n' ] || [ "$PONYSAY_FULL_WIDTH" = '0' ]; then + if [ "$PONYSAY_FULL_WIDTH" = 'yes' ] || [ "$PONYSAY_FULL_WIDTH" = 'y' ] || [ "$PONYSAY_FULL_WIDTH" = '1' ]; then cat else WIDTH=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2` -- cgit From d9d620f9809c8079d8c13ed4794a41f9f5857277 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 20 Jul 2012 05:46:58 +0200 Subject: fixing ponythink bug I introduced --- ponysay | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'ponysay') diff --git a/ponysay b/ponysay index 04ab745..10b031a 100755 --- a/ponysay +++ b/ponysay @@ -19,7 +19,14 @@ else cmd="$PONYSAY_COWSAY" customcmd=1 fi -[[ ${0} == *ponythink ]] && cmd=cowthink +[[ ${0} == *ponythink ]] && + if [[ "$PONYSAY_COWTHINK" = "" ]]; then + cmd=cowthink + customcmd=0 + else + cmd="$PONYSAY_COWTHINK" + customcmd=1 + fi version() { echo "ponysay v$version" @@ -73,7 +80,7 @@ _linklist() { scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2` - perl '/dev/stdin' $(echo $args) < /dev/shm/.ponysay~ + perl '/dev/stdin' $(echo $args) < '/dev/shm/.ponysay~' #!/usr/bin/perl #Author: Mattias Andrée (maandree@kth.se) @@ -140,7 +147,8 @@ while (\$i < \$argc) } EOF - perl $listcmd $scrw $(cat /dev/shm/.ponysay~) | sed -e 's/_/ /g' | qlist + perl $listcmd $scrw $(cat "/dev/shm/.ponysay~") | sed -e 's/_/ /g' | qlist + rm '/dev/shm/.ponysay~' } linklist() { @@ -217,13 +225,22 @@ say() { if [[ $customcmd = 0 ]]; then function cowcmd { + echo "standrd $cmd" pcmd='#!/usr/bin/perl\nuse utf8;' ccmd=$(for c in $(echo $PATH":" | sed -e 's/:/\/'"$cmd"' /g'); do if [[ -f $c ]]; then echo $c; break; fi done) - perl <(cat <(echo -e $pcmd) $ccmd) "$@" + echo "is $cmd" + if [[ ${0} == *ponythink ]]; then + cat <(echo -e $pcmd) $ccmd > "/dev/shm/.ponythink" + perl '/dev/shm/.ponythink' "$@" + rm '/dev/shm/.ponythink' + else + perl <(cat <(echo -e $pcmd) $ccmd) "$@" + fi } else function cowcmd { + echo "custom $cmd" $cmd "$@" } fi -- cgit From e48e73ef4bdf505d44a3189043a948677377d6d7 Mon Sep 17 00:00:00 2001 From: Elis Axelsson Date: Fri, 20 Jul 2012 18:07:59 +0200 Subject: Removed some weird echos and reindeted the full file --- ponysay | 321 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 162 insertions(+), 159 deletions(-) (limited to 'ponysay') diff --git a/ponysay b/ponysay index 10b031a..c856fd2 100755 --- a/ponysay +++ b/ponysay @@ -8,28 +8,29 @@ pony="*" wrap="" if [ "$TERM" = "linux" ]; then - SYSTEMPONIES="/usr/share/ponysay/ttyponies" - HOMEPONIES="${HOME}/.local/share/ponysay/ttyponies" + SYSTEMPONIES="/usr/share/ponysay/ttyponies" + HOMEPONIES="${HOME}/.local/share/ponysay/ttyponies" fi if [[ "$PONYSAY_COWSAY" = "" ]]; then - cmd=cowsay - customcmd=0 + cmd=cowsay + customcmd=0 else - cmd="$PONYSAY_COWSAY" - customcmd=1 + cmd="$PONYSAY_COWSAY" + customcmd=1 fi + [[ ${0} == *ponythink ]] && - if [[ "$PONYSAY_COWTHINK" = "" ]]; then +if [[ "$PONYSAY_COWTHINK" = "" ]]; then cmd=cowthink customcmd=0 - else +else cmd="$PONYSAY_COWTHINK" customcmd=1 - fi +fi version() { - echo "ponysay v$version" + echo "ponysay v$version" } scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2` @@ -38,49 +39,51 @@ truncatercmd="${SCRIPTDIR}/../lib/ponysay/truncater" haspq=1 if [[ -f './pq4ps-list' ]]; then - function qlist - { ./pq4ps-list - } + function qlist { + ./pq4ps-list + } elif [[ -f '/usr/bin/pq4ps-list' ]]; then - function qlist - { /usr/bin/pq4ps-list - } + function qlist { + /usr/bin/pq4ps-list + } else - haspq=0 - function qlist - { cat - } + haspq=0 + function qlist { + cat + } fi list() { - echo -e "\\e[01mponyfiles located in $SYSTEMPONIES:\\e[21m" - perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed -e 's/\.pony$//' | sort) | qlist - - if [[ -d $HOMEPONIES ]]; then - echo -e "\\e[01mponyfiles located in $HOMEPONIES:\\e[21m" - perl $listcmd $scrw $(ls --color=no $HOMEPONIES | sed -e 's/\.pony$//' | sort) | qlist - fi + echo -e "\\e[01mponyfiles located in $SYSTEMPONIES:\\e[21m" + perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed -e 's/\.pony$//' | sort) | qlist + + if [[ -d $HOMEPONIES ]]; then + echo -e "\\e[01mponyfiles located in $HOMEPONIES:\\e[21m" + perl $listcmd $scrw $(ls --color=no $HOMEPONIES | sed -e 's/\.pony$//' | sort) | qlist + 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~' + 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) @@ -146,21 +149,22 @@ while (\$i < \$argc) } } EOF - - perl $listcmd $scrw $(cat "/dev/shm/.ponysay~") | sed -e 's/_/ /g' | qlist - rm '/dev/shm/.ponysay~' + + perl $listcmd $scrw $(cat "/dev/shm/.ponysay~") | sed -e 's/_/ /g' | qlist + rm '/dev/shm/.ponysay~' } linklist() { - _linklist $SYSTEMPONIES - if [[ -d $HOMEPONIES ]]; then - _linklist $HOMEPONIES - fi + _linklist $SYSTEMPONIES + + if [[ -d $HOMEPONIES ]]; then + _linklist $HOMEPONIES + fi } usage() { - version - cat </dev/null || cat + # Ponies use UTF-8 drawing characters. Prevent a Perl warning. + export PERL_UNICODE=S + + if [ "$TERM" = "linux" ]; then + echo -ne '\e[H\e[2J' fi - } - - if [ "$PONYSAY_SHELL_LINES" = "" ]; then - PONYSAY_SHELL_LINES=2 - fi - function htrunchead - { - head --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES )) - } - function htrunctail - { - tail --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES )) - } - - if [[ $customcmd = 0 ]]; then - function cowcmd - { - echo "standrd $cmd" - pcmd='#!/usr/bin/perl\nuse utf8;' - ccmd=$(for c in $(echo $PATH":" | sed -e 's/:/\/'"$cmd"' /g'); do if [[ -f $c ]]; then echo $c; break; fi done) - echo "is $cmd" - if [[ ${0} == *ponythink ]]; then - cat <(echo -e $pcmd) $ccmd > "/dev/shm/.ponythink" - perl '/dev/shm/.ponythink' "$@" - rm '/dev/shm/.ponythink' - else - perl <(cat <(echo -e $pcmd) $ccmd) "$@" - fi + + function wtrunc { + if [ "$PONYSAY_FULL_WIDTH" = 'yes' ] || [ "$PONYSAY_FULL_WIDTH" = 'y' ] || [ "$PONYSAY_FULL_WIDTH" = '1' ]; then + cat + else + WIDTH=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2` + $truncatercmd $WIDTH 2>/dev/null || cat + fi } - else - function cowcmd - { - echo "custom $cmd" - $cmd "$@" + + if [ "$PONYSAY_SHELL_LINES" = "" ]; then + PONYSAY_SHELL_LINES=2 + fi + + function htrunchead { + head --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES )) + } + + function htrunctail { + tail --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES )) } - fi - - if [ "$TERM" = "linux" ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'yes' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'y' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = '1' ]; then - if [ "$PONYSAY_BOTTOM" = 'yes' ] || [ "$PONYSAY_BOTTOM" = 'y' ] || [ "$PONYSAY_BOTTOM" = '1' ]; then - cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunctail + + if [[ $customcmd = 0 ]]; then + function cowcmd { + pcmd='#!/usr/bin/perl\nuse utf8;' + ccmd=$(for c in $(echo $PATH":" | sed -e 's/:/\/'"$cmd"' /g'); do if [[ -f $c ]]; then echo $c; break; fi done) + + if [[ ${0} == *ponythink ]]; then + cat <(echo -e $pcmd) $ccmd > "/dev/shm/.ponythink" + perl '/dev/shm/.ponythink' "$@" + rm '/dev/shm/.ponythink' + else + perl <(cat <(echo -e $pcmd) $ccmd) "$@" + fi + } + else + function cowcmd { + echo "custom $cmd" + $cmd "$@" + } + fi + + if [ "$TERM" = "linux" ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'yes' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = 'y' ] || [ "$PONYSAY_TRUNCATE_HEIGHT" = '1' ]; then + if [ "$PONYSAY_BOTTOM" = 'yes' ] || [ "$PONYSAY_BOTTOM" = 'y' ] || [ "$PONYSAY_BOTTOM" = '1' ]; then + cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunctail + else + cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunchead + fi else - cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc | htrunchead + cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc fi - else - cowcmd -f "$pony" "${wrap:+-W$wrap}" | wtrunc - fi } ponies=() opts="f:W:Llhv" if [[ $haspq ]]; then - opts=$opts"q" + opts=$opts"q" fi + usepq=0 -while getopts $opts OPT -do - case ${OPT} in - v) version; exit ;; - h) usage; exit ;; - f) ponies+=( "$OPTARG" ) ;; - l) list; exit ;; - L) linklist; exit ;; - W) wrap="$OPTARG" ;; - q) usepq=1 ;; - \?) usage >&2; exit 1 ;; - esac +while getopts $opts OPT; do + case ${OPT} in + v) version; exit ;; + h) usage; exit ;; + f) ponies+=( "$OPTARG" ) ;; + l) list; exit ;; + L) linklist; exit ;; + W) wrap="$OPTARG" ;; + q) usepq=1 ;; + \?) usage >&2; exit 1 ;; + esac done shift $((OPTIND - 1)) if [[ $usepq = 1 ]]; then - if [[ -f './pq4ps' ]]; then - function q - { ./pq4ps $@ - } - elif [[ -f '/usr/bin/pq4ps' ]]; then - function q - { /usr/bin/pq4ps $@ - } - fi - $0 ${wrap:+-W$wrap} $(q "$*") - exit + if [[ -f './pq4ps' ]]; then + function q { + ./pq4ps $@ + } + elif [[ -f '/usr/bin/pq4ps' ]]; then + function q { + /usr/bin/pq4ps $@ + } + fi + $0 ${wrap:+-W$wrap} $(q "$*") + exit fi hash $cmd &>/dev/null; if [ $? -ne 0 ]; then - cat >&2 <&2 <&2 "All the ponies are missing! Call the Princess!" - exit 1 - fi - - # Choose a random pony - pony="${ponies[$RANDOM%${#ponies[@]}]}" + # Pony not a file? Search for it + + ponies=() + [[ -d $SYSTEMPONIES ]] && ponies+=( "$SYSTEMPONIES"/$pony.pony ) + [[ -d $HOMEPONIES ]] && ponies+=( "$HOMEPONIES"/$pony.pony ) + + if (( ${#ponies} < 1 )); then + echo >&2 "All the ponies are missing! Call the Princess!" + exit 1 + fi + + # Choose a random pony + pony="${ponies[$RANDOM%${#ponies[@]}]}" fi if [[ -n "$*" ]]; then - # Handle a message given via arguments - say <<<"$*" + # Handle a message given via arguments + say <<<"$*" else - say + say fi + -- cgit