From ce3fac588fb84a109244b9c3d60aba4fc247a86f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 18 Aug 2012 15:15:57 +0200 Subject: adding .sh to shell version + removing old files --- list.pl | 41 -------- ponysay | 294 ---------------------------------------------------------- ponysay.sh | 294 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pq4ps-list.pl | 24 ----- pq4ps.pl | 26 ------ 5 files changed, 294 insertions(+), 385 deletions(-) delete mode 100755 list.pl delete mode 100755 ponysay create mode 100755 ponysay.sh delete mode 100755 pq4ps-list.pl delete mode 100755 pq4ps.pl diff --git a/list.pl b/list.pl deleted file mode 100755 index 2004484..0000000 --- a/list.pl +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env perl - -# ponysaylist -# Prints a list of ponies in columns -# -# Licensed under WTFPL -# See COPYING for details - -# Author: Mattias Andrée, maandree@kth.se -# spider-mario - - -use strict; -use warnings; -use utf8; -use feature qw(say); -use integer; -use List::Util qw(max); - -my $scrw = shift @ARGV // 1; - -#for (@ARGV) { -# # Format names from pony names -# s/(?<=[a-z])(?=[A-Z])/ /; -# s/_(.*)/\t($1)/; -#} - -my $maxw = max 1, map {length} @ARGV; - -my $cols = max 1, (($scrw + 2) / ($maxw + 2)); - -my @list = map {sprintf "%-${maxw}s", $_} @ARGV; - -my $rows = (@list + $cols - 1) / $cols; - -my @rowlist; -for my $i (0 .. $#list) { - push @{$rowlist[$i % $rows]}, $list[$i]; -} - -say join ' ', @$_ for @rowlist; diff --git a/ponysay b/ponysay deleted file mode 100755 index 9936fae..0000000 --- a/ponysay +++ /dev/null @@ -1,294 +0,0 @@ -#!/usr/bin/env bash - -VERSION=1.4.1 - - - -# Get bash script directory's parent -INSTALLDIR="$(dirname $( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd ))" - -# Directory for installed media files -SYSTEMSHARE="$INSTALLDIR/share/ponysay" -HOMESHARE="${HOME}/.local/share/ponysay" - -# Subscripts -listcmd="$INSTALLDIR/lib/ponysay/list.pl" -linklistcmd="$INSTALLDIR/lib/ponysay/linklist.pl" -truncatercmd="$INSTALLDIR/lib/ponysay/truncater" -quotecmd="$INSTALLDIR/lib/ponysay/pq4ps" -qlistcmd="$INSTALLDIR/lib/ponysay/pq4ps-list.pl" - -pony="*" # Selected pony -wrap="" # Message wrap column -ponies=() # Selected ponies - -scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2` # Screen width -scrh=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 1` # Screen height - -# KMS ponies extension -kmscmd="" -[ "$TERM" = "linux" ] && kmscmd=$(for c in $(echo $PATH":" | sed -e 's/:/\/ponysay2kmsponysay /g'); do if [ -f $c ]; then echo $c; break; fi done) -[ ! "$kmscmd" = "" ] && TERM="-linux-" - -# Directories for installed ponies files -if [ "$TERM" = "linux" ]; then - SYSTEMPONIES="$SYSTEMSHARE/ttyponies" - HOMEPONIES="$HOMESHARE/ttyponies" -else - SYSTEMPONIES="$SYSTEMSHARE/ponies" - HOMEPONIES="$HOMESHARE/ponies" -fi - -# Cowsay script -if [ ${0} == *ponythink ]; then - if [ "$PONYSAY_COWTHINK" = "" ]; then - cmd=cowthink - customcmd=0 - else - cmd="$PONYSAY_COWTHINK" - customcmd=1 - fi -else - if [ "$PONYSAY_COWSAY" = "" ]; then - cmd=cowsay - customcmd=0 - else - cmd="$PONYSAY_COWSAY" - customcmd=1 - fi -fi - - - -# Ponysay version print function -version() { - echo "ponysay v$VERSION" -} - -# Marks ponies in lists that have quotes -qoutelist() { - bash -c "$("$qlistcmd" $("$quotecmd" --list))" -} - -# Pony list function -list() { - if [ -d $SYSTEMPONIES ]; then - echo -e "\\e[01mponyfiles located in $SYSTEMPONIES:\\e[21m" - perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed -e 's/\.pony$//' | sort) | qoutelist - fi - 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) | qoutelist - fi - if [ ! -d $SYSTEMPONIES ] && [ ! -d $HOMEPONIES ]; then - echo >&2 "All the ponies are missing! Call the Princess!" - fi -} - -# Pony list function with symlink map, for one directory -_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 - - perl $listcmd $scrw $(perl $linklistcmd $(echo $args) | sed -e 's/ /_/g') | sed -e 's/_/ /g' | qoutelist -} - -# Pony list function with symlink map, for both directories -linklist() { - _linklist $SYSTEMPONIES - - if [ -d $HOMEPONIES ]; then - _linklist $HOMEPONIES - fi -} - -# Pony quotes -ponyquotes() { - [ "$TERM" = "-linux-" ] && TERM="linux" - "$0" ${wrap:+-W$wrap} $("$quotecmd" $@) -} - -# Usage help print function -usage() { - version - cat < "/tmp/ponythink" - perl '/tmp/ponythink' "$@" - rm '/tmp/ponythink' - else - perl <(cat <(echo -e $pcmd) $ccmd) "$@" - fi - } - else - function cowcmd { - $cmd "$@" - } - fi - - # KMS ponies support - if [ "$kmscmd" = "" ]; then - function runcmd { - cowcmd -f "$pony" "$@" - } - else - function runcmd { - cowcmd -f <($kmscmd "$pony") "$@" - } - fi - - # Print the pony and the message - 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 - runcmd "${wrap:+-W$wrap}" | wtrunc | htrunctail - else - runcmd "${wrap:+-W$wrap}" | wtrunc | htrunchead - fi - else - runcmd "${wrap:+-W$wrap}" | wtrunc - fi -} - - - -# If no stdin and no arguments then print usage and exit -if [ -t 0 ] && [ $# == 0 ]; then - usage - exit -fi - - - -# Parse options -while getopts "f:W:Llhvq" OPT; do - case ${OPT} in - v) version; exit ;; - h) usage; exit ;; - f) ponies+=( $OPTARG ) ;; - l) list; exit ;; - L) linklist; exit ;; - W) wrap="$OPTARG" ;; - q) shift $((OPTIND - 1)); ponyquotes "$*"; exit ;; - \?) usage >&2; exit 1 ;; - esac -done -shift $((OPTIND - 1)) - - -# Check for cowsay -hash $cmd &>/dev/null; if [ $? -ne 0 ]; then - cat >&2 <&2 "All the ponies are missing! Call the Princess!" - exit 1 - fi - - # Choose a random pony - pony="${ponies[$RANDOM%${#ponies[@]}]}" -fi - - -# Print pony with message -if [ -n "$*" ]; then - # Handle a message given via arguments - say <<<"$*" -else - # Handle a message given in stdin - say -fi - diff --git a/ponysay.sh b/ponysay.sh new file mode 100755 index 0000000..9936fae --- /dev/null +++ b/ponysay.sh @@ -0,0 +1,294 @@ +#!/usr/bin/env bash + +VERSION=1.4.1 + + + +# Get bash script directory's parent +INSTALLDIR="$(dirname $( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd ))" + +# Directory for installed media files +SYSTEMSHARE="$INSTALLDIR/share/ponysay" +HOMESHARE="${HOME}/.local/share/ponysay" + +# Subscripts +listcmd="$INSTALLDIR/lib/ponysay/list.pl" +linklistcmd="$INSTALLDIR/lib/ponysay/linklist.pl" +truncatercmd="$INSTALLDIR/lib/ponysay/truncater" +quotecmd="$INSTALLDIR/lib/ponysay/pq4ps" +qlistcmd="$INSTALLDIR/lib/ponysay/pq4ps-list.pl" + +pony="*" # Selected pony +wrap="" # Message wrap column +ponies=() # Selected ponies + +scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2` # Screen width +scrh=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 1` # Screen height + +# KMS ponies extension +kmscmd="" +[ "$TERM" = "linux" ] && kmscmd=$(for c in $(echo $PATH":" | sed -e 's/:/\/ponysay2kmsponysay /g'); do if [ -f $c ]; then echo $c; break; fi done) +[ ! "$kmscmd" = "" ] && TERM="-linux-" + +# Directories for installed ponies files +if [ "$TERM" = "linux" ]; then + SYSTEMPONIES="$SYSTEMSHARE/ttyponies" + HOMEPONIES="$HOMESHARE/ttyponies" +else + SYSTEMPONIES="$SYSTEMSHARE/ponies" + HOMEPONIES="$HOMESHARE/ponies" +fi + +# Cowsay script +if [ ${0} == *ponythink ]; then + if [ "$PONYSAY_COWTHINK" = "" ]; then + cmd=cowthink + customcmd=0 + else + cmd="$PONYSAY_COWTHINK" + customcmd=1 + fi +else + if [ "$PONYSAY_COWSAY" = "" ]; then + cmd=cowsay + customcmd=0 + else + cmd="$PONYSAY_COWSAY" + customcmd=1 + fi +fi + + + +# Ponysay version print function +version() { + echo "ponysay v$VERSION" +} + +# Marks ponies in lists that have quotes +qoutelist() { + bash -c "$("$qlistcmd" $("$quotecmd" --list))" +} + +# Pony list function +list() { + if [ -d $SYSTEMPONIES ]; then + echo -e "\\e[01mponyfiles located in $SYSTEMPONIES:\\e[21m" + perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed -e 's/\.pony$//' | sort) | qoutelist + fi + 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) | qoutelist + fi + if [ ! -d $SYSTEMPONIES ] && [ ! -d $HOMEPONIES ]; then + echo >&2 "All the ponies are missing! Call the Princess!" + fi +} + +# Pony list function with symlink map, for one directory +_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 + + perl $listcmd $scrw $(perl $linklistcmd $(echo $args) | sed -e 's/ /_/g') | sed -e 's/_/ /g' | qoutelist +} + +# Pony list function with symlink map, for both directories +linklist() { + _linklist $SYSTEMPONIES + + if [ -d $HOMEPONIES ]; then + _linklist $HOMEPONIES + fi +} + +# Pony quotes +ponyquotes() { + [ "$TERM" = "-linux-" ] && TERM="linux" + "$0" ${wrap:+-W$wrap} $("$quotecmd" $@) +} + +# Usage help print function +usage() { + version + cat < "/tmp/ponythink" + perl '/tmp/ponythink' "$@" + rm '/tmp/ponythink' + else + perl <(cat <(echo -e $pcmd) $ccmd) "$@" + fi + } + else + function cowcmd { + $cmd "$@" + } + fi + + # KMS ponies support + if [ "$kmscmd" = "" ]; then + function runcmd { + cowcmd -f "$pony" "$@" + } + else + function runcmd { + cowcmd -f <($kmscmd "$pony") "$@" + } + fi + + # Print the pony and the message + 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 + runcmd "${wrap:+-W$wrap}" | wtrunc | htrunctail + else + runcmd "${wrap:+-W$wrap}" | wtrunc | htrunchead + fi + else + runcmd "${wrap:+-W$wrap}" | wtrunc + fi +} + + + +# If no stdin and no arguments then print usage and exit +if [ -t 0 ] && [ $# == 0 ]; then + usage + exit +fi + + + +# Parse options +while getopts "f:W:Llhvq" OPT; do + case ${OPT} in + v) version; exit ;; + h) usage; exit ;; + f) ponies+=( $OPTARG ) ;; + l) list; exit ;; + L) linklist; exit ;; + W) wrap="$OPTARG" ;; + q) shift $((OPTIND - 1)); ponyquotes "$*"; exit ;; + \?) usage >&2; exit 1 ;; + esac +done +shift $((OPTIND - 1)) + + +# Check for cowsay +hash $cmd &>/dev/null; if [ $? -ne 0 ]; then + cat >&2 <&2 "All the ponies are missing! Call the Princess!" + exit 1 + fi + + # Choose a random pony + pony="${ponies[$RANDOM%${#ponies[@]}]}" +fi + + +# Print pony with message +if [ -n "$*" ]; then + # Handle a message given via arguments + say <<<"$*" +else + # Handle a message given in stdin + say +fi + diff --git a/pq4ps-list.pl b/pq4ps-list.pl deleted file mode 100755 index d4517c5..0000000 --- a/pq4ps-list.pl +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/perl - -print "(sed"; - -foreach $arg (@ARGV) -{ - print " -e 's/ $arg / \e[1m$arg\e[21m /g'"; - print " -e 's/ $arg)/ \e[1m$arg\e[21m)/g'"; - print " -e 's/($arg /(\e[1m$arg\e[21m /g'"; - print " -e 's/($arg)/(\e[1m$arg\e[21m)/g'"; - print " -e 's/ $arg\$/ \e[1m$arg\e[21m/g'"; - print " -e 's/^$arg /\e[1m$arg\e[21m /g'"; - print " -e 's/^$arg\$/\e[1m$arg\e[21m/g'"; -} - -print " | sed"; - -foreach $arg (@ARGV) -{ - print " -e 's/ $arg)/ \e[1m$arg\e[21m)/g'"; - print " -e 's/ $arg\$/ \e[1m$arg\e[21m/g'" -} - -print ")"; diff --git a/pq4ps.pl b/pq4ps.pl deleted file mode 100755 index 2f45053..0000000 --- a/pq4ps.pl +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/perl - -opendir(DIR, $ARGV[0]."/share/ponysay/ponies/"); -@files = readdir(DIR); - -opendir(DIR, $ARGV[0]."/share/ponysay/quotes/"); -@quotes = readdir(DIR); - - -foreach $file (@files) -{ - $_ = $file; - $_ =~ s/\.pony$//g; - $f = $_; - if (! /^\./) - { foreach $quote (@quotes) - { - $_ = $quote; - $_ =~ s/\.\d+//g; - $_ = '+'.$_.'+'; - if (! /^\./) - { if (/\+$f\+/) - { print $f."@".$quote."\n"; - } } - } } -} -- cgit