From 70c27ca36f696b12012d7f47ac3071f747b95207 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 1 Aug 2012 03:33:30 +0200 Subject: some edits --- .gitignore | 2 +- CHANGELOG | 9 +- Makefile | 65 +++++++------ bin/ponysay | 1 + completion/bash-completion.sh | 2 +- lib/ponysay/linklist.pl | 1 + lib/ponysay/list.pl | 1 + lib/ponysay/pq4ps | 1 + lib/ponysay/pq4ps-list | 1 + lib/ponysay/pq4ps-list.pl | 1 + lib/ponysay/pq4ps.pl | 1 + linklist.pl | 35 +++++++ list.pl | 41 ++++++++ manuals/ponysay.texinfo | 2 + ponies/elsie.pony | 1 + ponysay | 222 +++++++++++++++++++++--------------------- ponysay.pdf | Bin 318391 -> 319214 bytes ponysaylinklist.pl | 36 ------- ponysaylist.pl | 41 -------- ponysaytruncater.c | 153 ----------------------------- pq4ps | 14 +-- pq4ps-list | 6 +- pq4ps.pl | 4 +- share/ponysay/ponies | 1 + share/ponysay/quotes | 1 + share/ponysay/ttyponies | 1 + truncater.c | 153 +++++++++++++++++++++++++++++ ttyponies/elsie.pony | 1 + 28 files changed, 408 insertions(+), 389 deletions(-) create mode 120000 bin/ponysay create mode 120000 lib/ponysay/linklist.pl create mode 120000 lib/ponysay/list.pl create mode 120000 lib/ponysay/pq4ps create mode 120000 lib/ponysay/pq4ps-list create mode 120000 lib/ponysay/pq4ps-list.pl create mode 120000 lib/ponysay/pq4ps.pl create mode 100755 linklist.pl create mode 100755 list.pl create mode 120000 ponies/elsie.pony delete mode 100755 ponysaylinklist.pl delete mode 100755 ponysaylist.pl delete mode 100644 ponysaytruncater.c create mode 120000 share/ponysay/ponies create mode 120000 share/ponysay/quotes create mode 120000 share/ponysay/ttyponies create mode 100644 truncater.c create mode 120000 ttyponies/elsie.pony diff --git a/.gitignore b/.gitignore index 2f8f23f..a55bb47 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,5 @@ /completion/*-completion-think.* /manuals/manpage.*.gz /ponysay.info.gz -/ponysaytruncater +/truncater diff --git a/CHANGELOG b/CHANGELOG index 5566ad2..228cc95 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Version 1.3 - New Ponies: forestspirit, raggedy, rhyme + New ponies: forestspirit, raggedy, rhyme + Version 1.2 @@ -8,8 +9,8 @@ Version 1.2 Support for extension: kmsponies4ponysay. - New ponies: ace, filthyrich, blueblood, gingergold, hayfever, - highscore, junebug, mrsparkle, persnickety, ponet, + New ponies: ace, filthyrich, blueblood, gingergold, hayfever, + highscore, junebug, mrsparkle, persnickety, ponet, screwloose, tornadobolt. Pony symlinks added: mrsparkle → nightlight @@ -19,6 +20,8 @@ Version 1.2 Arbitrary spaces in '-f' argument is not longer accepted (it causes problems with file names including spaces). + Note: Identifies itself as version 1.1 + Version 1.1 diff --git a/Makefile b/Makefile index a5ec6b4..570e265 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ -all: ponysaytruncater manpages infomanual ponythinkcompletion +all: truncater manpages infomanual ponythinkcompletion -ponysaytruncater: - gcc -o "ponysaytruncater" "ponysaytruncater.c" +truncater: + gcc -o "truncater" "truncater.c" manpages: - gzip -9 < "manuals/manpage.6" > "manuals/manpage.6.gz" + gzip -9 < "manuals/manpage.6" > "manuals/manpage.6.gz" gzip -9 < "manuals/manpage.es.6" > "manuals/manpage.es.6.gz" infomanual: makeinfo "manuals/ponysay.texinfo" - gzip -9 "ponysay.info" + gzip -9 "ponysay.info" ponythinkcompletion: sed -e 's/ponysay/ponythink/g' <"completion/bash-completion.sh" | sed -e 's/\/ponythink\//\/ponysay\//g' -e 's/\\\/ponythink\\\//\\\/ponysay\\\//g' >"completion/bash-completion-think.sh" @@ -21,47 +21,47 @@ install: all mkdir -p "$(DESTDIR)/usr/share/ponysay/ponies" mkdir -p "$(DESTDIR)/usr/share/ponysay/ttyponies" mkdir -p "$(DESTDIR)/usr/share/ponysay/quotes" - cp -P ponies/*.pony "$(DESTDIR)/usr/share/ponysay/ponies/" + cp -P ponies/*.pony "$(DESTDIR)/usr/share/ponysay/ponies/" cp -P ttyponies/*.pony "$(DESTDIR)/usr/share/ponysay/ttyponies/" - cp -P quotes/*.* "$(DESTDIR)/usr/share/ponysay/quotes/" + cp -P quotes/*.* "$(DESTDIR)/usr/share/ponysay/quotes/" - mkdir -p "$(DESTDIR)/usr/bin/" + mkdir -p "$(DESTDIR)/usr/bin/" install "ponysay" "$(DESTDIR)/usr/bin/ponysay" - ln -sf "ponysay" "$(DESTDIR)/usr/bin/ponythink" - install "pq4ps" "$(DESTDIR)/usr/bin/pq4ps" - install "pq4ps.pl" "$(DESTDIR)/usr/bin/pq4ps.pl" - install "pq4ps-list" "$(DESTDIR)/usr/bin/pq4ps-list" - install "pq4ps-list.pl" "$(DESTDIR)/usr/bin/pq4ps-list.pl" - - mkdir -p "$(DESTDIR)/usr/lib/ponysay/" - install -s "ponysaytruncater" "$(DESTDIR)/usr/lib/ponysay/truncater" - install "ponysaylist.pl" "$(DESTDIR)/usr/lib/ponysay/list.pl" - install "ponysaylinklist.pl" "$(DESTDIR)/usr/lib/ponysay/linklist.pl" - - mkdir -p "$(DESTDIR)/usr/share/bash-completion/completions/" - install "completion/bash-completion.sh" "$(DESTDIR)/usr/share/bash-completion/completions/ponysay" + ln -sf "ponysay" "$(DESTDIR)/usr/bin/ponythink" + + mkdir -p "$(DESTDIR)/usr/lib/ponysay/" + install -s "truncater" "$(DESTDIR)/usr/lib/ponysay/truncater" + install "list.pl" "$(DESTDIR)/usr/lib/ponysay/list.pl" + install "linklist.pl" "$(DESTDIR)/usr/lib/ponysay/linklist.pl" + install "pq4ps" "$(DESTDIR)/usr/lib/pq4ps" + install "pq4ps.pl" "$(DESTDIR)/usr/lib/pq4ps.pl" + install "pq4ps-list" "$(DESTDIR)/usr/lib/pq4ps-list" + install "pq4ps-list.pl" "$(DESTDIR)/usr/lib/pq4ps-list.pl" + + mkdir -p "$(DESTDIR)/usr/share/bash-completion/completions/" + install "completion/bash-completion.sh" "$(DESTDIR)/usr/share/bash-completion/completions/ponysay" install "completion/bash-completion-think.sh" "$(DESTDIR)/usr/share/bash-completion/completions/ponythink" - mkdir -p "$(DESTDIR)/usr/share/fish/completions/" - install "completion/fish-completion.fish" "$(DESTDIR)/usr/share/fish/completions/ponysay.fish" + mkdir -p "$(DESTDIR)/usr/share/fish/completions/" + install "completion/fish-completion.fish" "$(DESTDIR)/usr/share/fish/completions/ponysay.fish" install "completion/fish-completion-think.fish" "$(DESTDIR)/usr/share/fish/completions/ponythink.fish" - mkdir -p "$(DESTDIR)/usr/share/zsh/site-functions/" - install "completion/zsh-completion.zsh" "$(DESTDIR)/usr/share/zsh/site-functions/_ponysay" + mkdir -p "$(DESTDIR)/usr/share/zsh/site-functions/" + install "completion/zsh-completion.zsh" "$(DESTDIR)/usr/share/zsh/site-functions/_ponysay" install "completion/zsh-completion-think.zsh" "$(DESTDIR)/usr/share/zsh/site-functions/_ponythink" - mkdir -p "$(DESTDIR)/usr/share/licenses/ponysay/" + mkdir -p "$(DESTDIR)/usr/share/licenses/ponysay/" install "COPYING" "$(DESTDIR)/usr/share/licenses/ponysay/COPYING" - mkdir -p "$(DESTDIR)/usr/share/man/man6" + mkdir -p "$(DESTDIR)/usr/share/man/man6" install "manuals/manpage.6.gz" "$(DESTDIR)/usr/share/man/man6/ponysay.6.gz" - ln -sf "ponysay.6.gz" "$(DESTDIR)/usr/share/man/man6/ponythink.6.gz" + ln -sf "ponysay.6.gz" "$(DESTDIR)/usr/share/man/man6/ponythink.6.gz" - mkdir -p "$(DESTDIR)/usr/share/man/es/man6" + mkdir -p "$(DESTDIR)/usr/share/man/es/man6" install "manuals/manpage.es.6.gz" "$(DESTDIR)/usr/share/man/es/man6/ponysay.6.gz" - ln -sf "ponysay.6.gz" "$(DESTDIR)/usr/share/man/es/man6/ponythink.6.gz" + ln -sf "ponysay.6.gz" "$(DESTDIR)/usr/share/man/es/man6/ponythink.6.gz" - mkdir -p "$(DESTDIR)/usr/share/info" + mkdir -p "$(DESTDIR)/usr/share/info" install "ponysay.info.gz" "$(DESTDIR)/usr/share/info/ponysay.info.gz" install "ponysay.info.gz" "$(DESTDIR)/usr/share/info/ponythink.info.gz" install-info --dir-file="$(DESTDIR)/usr/share/info/dir" --entry="Miscellaneous" --description="My Little Ponies for your terminal" "$(DESTDIR)/usr/share/info/ponysay.info.gz" @@ -139,7 +139,7 @@ ttyponies: pdfmanual: texi2pdf "manuals/ponysay.texinfo" - git add "manuals/ponysay.texinfo" + git add "manuals/ponysay.texinfo" "ponysay.pdf" if [[ -f "ponysay.aux" ]]; then unlink "ponysay.aux"; fi if [[ -f "ponysay.cp" ]]; then unlink "ponysay.cp" ; fi if [[ -f "ponysay.cps" ]]; then unlink "ponysay.cps"; fi @@ -161,3 +161,4 @@ quotes: submodules mkdir -p "quotes" cp "ponyquotes4ponysay/ponyquotes/"*.* "quotes" git add "quotes/"*.* + diff --git a/bin/ponysay b/bin/ponysay new file mode 120000 index 0000000..4f77813 --- /dev/null +++ b/bin/ponysay @@ -0,0 +1 @@ +../ponysay \ No newline at end of file diff --git a/completion/bash-completion.sh b/completion/bash-completion.sh index 53c53ef..92b1ef6 100644 --- a/completion/bash-completion.sh +++ b/completion/bash-completion.sh @@ -5,7 +5,7 @@ _ponysay() local cur prev words cword _init_completion -n = || return - quotes=$(pq4ps --list 2>/dev/null) + quotes=$(/usr/lib/ponysay/pq4ps --list 2>/dev/null) quotesexit=$? options='-v -h -l -f -W' if [[ $quotesexit = 0 ]]; then diff --git a/lib/ponysay/linklist.pl b/lib/ponysay/linklist.pl new file mode 120000 index 0000000..c3bdca4 --- /dev/null +++ b/lib/ponysay/linklist.pl @@ -0,0 +1 @@ +../../linklist.pl \ No newline at end of file diff --git a/lib/ponysay/list.pl b/lib/ponysay/list.pl new file mode 120000 index 0000000..1446e25 --- /dev/null +++ b/lib/ponysay/list.pl @@ -0,0 +1 @@ +../../list.pl \ No newline at end of file diff --git a/lib/ponysay/pq4ps b/lib/ponysay/pq4ps new file mode 120000 index 0000000..8fcf18f --- /dev/null +++ b/lib/ponysay/pq4ps @@ -0,0 +1 @@ +../../pq4ps \ No newline at end of file diff --git a/lib/ponysay/pq4ps-list b/lib/ponysay/pq4ps-list new file mode 120000 index 0000000..78c69af --- /dev/null +++ b/lib/ponysay/pq4ps-list @@ -0,0 +1 @@ +../../pq4ps-list \ No newline at end of file diff --git a/lib/ponysay/pq4ps-list.pl b/lib/ponysay/pq4ps-list.pl new file mode 120000 index 0000000..d26a31f --- /dev/null +++ b/lib/ponysay/pq4ps-list.pl @@ -0,0 +1 @@ +../../pq4ps-list.pl \ No newline at end of file diff --git a/lib/ponysay/pq4ps.pl b/lib/ponysay/pq4ps.pl new file mode 120000 index 0000000..31f9221 --- /dev/null +++ b/lib/ponysay/pq4ps.pl @@ -0,0 +1 @@ +../../pq4ps.pl \ No newline at end of file diff --git a/linklist.pl b/linklist.pl new file mode 100755 index 0000000..c0377aa --- /dev/null +++ b/linklist.pl @@ -0,0 +1,35 @@ +#!/usr/bin/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; + +my %hash; + +{ + local @ARGV = @ARGV; + while ((my ($source, $target), @ARGV) = @ARGV) { + unless ($source eq $target) { + push @{$hash{$target}}, $source; + } + } +} + +while ((my ($source, $target), @ARGV) = @ARGV) { + if ($source eq $target) { + my @list = @{$hash{$source} // []}; + print $source; + print ' (', join(' ', @list), ')' if @list; + print "\n"; + } +} diff --git a/list.pl b/list.pl new file mode 100755 index 0000000..2004484 --- /dev/null +++ b/list.pl @@ -0,0 +1,41 @@ +#!/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/manuals/ponysay.texinfo b/manuals/ponysay.texinfo index adacb54..3043a6a 100644 --- a/manuals/ponysay.texinfo +++ b/manuals/ponysay.texinfo @@ -849,6 +849,8 @@ Arbitrary spaces in @command{-f} argument is not longer accepted (it causes prob file names including spaces.) @end itemize +@b{Note}: Identifies itself as version 1.1 + @heading Version 1.1 @itemize @bullet diff --git a/ponies/elsie.pony b/ponies/elsie.pony new file mode 120000 index 0000000..acc1800 --- /dev/null +++ b/ponies/elsie.pony @@ -0,0 +1 @@ +./prettyvision.pony \ No newline at end of file diff --git a/ponysay b/ponysay index 52439c4..7ec14ba 100755 --- a/ponysay +++ b/ponysay @@ -1,80 +1,86 @@ #!/usr/bin/env bash -version=1.1 -SCRIPTDIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Get bash script directory -pony="*" -wrap="" +VERSION=1.3 -SYSTEMPONIES="$(dirname $SCRIPTDIR)/share/ponysay" -HOMEPONIES="${HOME}/.local/share/ponysay" + +# 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" +qlistcmd="$INSTALLDIR/lib/ponysay/pq4ps-list" +quotecmd="$INSTALLDIR/lib/ponysay/pq4ps" + +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="$SYSTEMPONIES/ttyponies" - HOMEPONIES="$HOMEPONIES/ttyponies" + SYSTEMPONIES="$SYSTEMSHARE/ttyponies" + HOMEPONIES="$HOMESHARE/ttyponies" else - SYSTEMPONIES="$SYSTEMPONIES/ponies" - HOMEPONIES="$HOMEPONIES/ponies" + SYSTEMPONIES="$SYSTEMSHARE/ponies" + HOMEPONIES="$HOMESHARE/ponies" fi -if [[ "$PONYSAY_COWSAY" = "" ]]; then - cmd=cowsay - customcmd=0 +# Cowsay script +if [[ ${0} == *ponythink ]]; then + if [[ "$PONYSAY_COWTHINK" = "" ]]; then + cmd=cowthink + customcmd=0 + else + cmd="$PONYSAY_COWTHINK" + customcmd=1 + fi else - cmd="$PONYSAY_COWSAY" - customcmd=1 + if [[ "$PONYSAY_COWSAY" = "" ]]; then + cmd=cowsay + customcmd=0 + else + cmd="$PONYSAY_COWSAY" + customcmd=1 + fi fi -[[ ${0} == *ponythink ]] && -if [[ "$PONYSAY_COWTHINK" = "" ]]; then - cmd=cowthink - customcmd=0 -else - cmd="$PONYSAY_COWTHINK" - customcmd=1 -fi + +# Ponysay version print function version() { - echo "ponysay v$version" + echo "ponysay v$VERSION" } -scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2` -listcmd="${SCRIPTDIR}/../lib/ponysay/list.pl" -linklistcmd="${SCRIPTDIR}/../lib/ponysay/linklist.pl" -truncatercmd="${SCRIPTDIR}/../lib/ponysay/truncater" -[[ -f "./ponysaylist.pl" ]] && listcmd="./ponysaylist.pl" -[[ -f "./ponysaylinklist.pl" ]] && linklistcmd="./ponysaylinklist.pl" -[[ -f "./ponysaytruncater" ]] && truncatercmd="./ponysaytruncater" - -haspq=1 -if [[ -f './pq4ps-list' ]]; then - function qlist { - ./pq4ps-list - } -elif [[ -f '/usr/bin/pq4ps-list' ]]; then - function qlist { - /usr/bin/pq4ps-list - } -else - haspq=0 - function qlist { - cat - } -fi - +# Pony list function 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 $SYSTEMPONIES ]]; then + echo -e "\\e[01mponyfiles located in $SYSTEMPONIES:\\e[21m" + perl $listcmd $scrw $(ls --color=no $SYSTEMPONIES | sed -e 's/\.pony$//' | sort) | $qlistcmd + 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) | qlist + perl $listcmd $scrw $(ls --color=no $HOMEPONIES | sed -e 's/\.pony$//' | sort) | $qlistcmd + 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) @@ -93,11 +99,10 @@ _linklist() { args=$(echo $args $file $target) done - scrw=`(stty size <&2 || echo 0 0) | cut -d ' ' -f 2` - - perl $listcmd $scrw $(perl $linklistcmd $(echo $args) | sed -e 's/ /_/g') | sed -e 's/_/ /g' | qlist + perl $listcmd $scrw $(perl $linklistcmd $(echo $args) | sed -e 's/ /_/g') | sed -e 's/_/ /g' | $qlistcmd } +# Pony list function with symlink map, for both directories linklist() { _linklist $SYSTEMPONIES @@ -106,6 +111,13 @@ linklist() { fi } +# Pony quotes +ponyquotes() { + [[ "$TERM" = "-linux-" ]] && TERM="linux" + "$0" ${wrap:+-W$wrap} $("$quotecmd" "$*") +} + +# Usage help print function usage() { version cat </dev/null || cat + if [[ -f $truncatercmd ]]; then + $truncatercmd $scrw + else + cat + fi fi } - - if [ "$PONYSAY_SHELL_LINES" = "" ]; then - PONYSAY_SHELL_LINES=2 - fi - + + # Height trunction, show top function htrunchead { - head --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES )) + head --lines=$(( $scrh - $PONYSAY_SHELL_LINES )) } - + + # Height trunction, show bottom function htrunctail { - tail --lines=$(( `stty size <&2 | cut -d ' ' -f 1` - $PONYSAY_SHELL_LINES )) + tail --lines=$(( $scrh - $PONYSAY_SHELL_LINES )) } - + + # Simplification of customisation of cowsay if [[ $customcmd = 0 ]]; then function cowcmd { pcmd='#!/usr/bin/perl\nuse utf8;' @@ -186,11 +190,11 @@ say() { } else function cowcmd { - echo "custom $cmd" $cmd "$@" } fi - + + # KMS ponies support if [[ "$kmscmd" = "" ]]; then function runcmd { cowcmd -f "$pony" "$@" @@ -200,7 +204,8 @@ say() { 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 @@ -212,15 +217,18 @@ say() { fi } -ponies=() -opts="f:W:Llhv" -if [[ $haspq ]]; then - opts=$opts"q" + +# If no stdin and no arguments then print usage and exit +if [[ -t 0 && $# == 0 ]]; then + usage + exit fi -usepq=0 -while getopts $opts OPT; do + + +# Parse options +while getopts "f:W:Llhvq" OPT; do case ${OPT} in v) version; exit ;; h) usage; exit ;; @@ -228,27 +236,14 @@ while getopts $opts OPT; do l) list; exit ;; L) linklist; exit ;; W) wrap="$OPTARG" ;; - q) usepq=1 ;; + q) ponyquotes; exit ;; \?) 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 - [[ "$TERM" = "-linux-" ]] && TERM="linux" - $0 ${wrap:+-W$wrap} $(q "$*") - exit -fi +# Check for cowsay hash $cmd &>/dev/null; if [ $? -ne 0 ]; then cat >&2 < -#define String char* -#define boolean char -#define true 1 -#define false 0 - -/* Stdin file descriptor ID */ -#define STDIN 0 - -/* The number of columns on the current line */ -static int col = 0; - -/* Escape sequence state */ -static int esc = 0; - -/* Last bytes as written */ -static boolean ok = true; - -void write(char b, int width); -int toInt(String string); - - -/* Mane method! - * The only argument, in addition to the executed file, - * should be the width of the terminal which you get by - * adding `tput cols || echo 0` as an argument. - * - * @param argc The number of startup arguments - * @param argv The startup arguments, the first is the file itself - * - * @author Mattias Andrée, maandree@kth.se - */ -void main(int argc, String* argv) -{ - int width = 0; - if (argc > 1) - width = toInt(*(argv + 1)); - - char b = 0; - - if (width > 15) /* sanity */ - while (read(STDIN, &b, 1)) - write(b, width); - else - while (read(STDIN, &b, 1)) - printf("%c", b); -} - -/* Writes a character to stdout, iff it fits within the terminal - * - * @param b The character (byte) to write - * @param width The width of the terminal - */ -void write(char b, int width) -{ - int i; - char tabstop; - - if (esc == 0) - { - if (b == '\n') - { - if (col >= width) - { - /* Reset background colour */ - write('\e', width); - write('[', width); - write('4', width); - write('9', width); - write('m', width); - } - col = -1; - } - else if (b == '\t') - { - /* Tab to next pos ≡₈ 0 */ - tabstop = 8 - (col & 7); - for (i = 0; i < tabstop; i++) - write(' ', width); - return; /* (!) */ - } - else if (b == '\e') - esc = 1; - } - else if (esc == 1) - { - if (b == '[') esc = 2; /* CSI: CSI ends with a letter, m is for colour */ - else if (b == ']') esc = 3; /* OSI: OSI P is for palette editing in Linux VT */ - else esc = 10; /* Nothing to see here, move along */ - } - else if (esc == 2) - { - if ((('a' <= b) && (b <= 'z')) || (('A' <= b) && (b <= 'Z'))) - esc = 10; - } - else if ((esc == 3) && (b == 'P')) - { - esc = ~0; - } - else if (esc < 0) - { - esc--; - if (esc == ~7) - esc = 10; - } - else - esc = 10; - - if ( - /* Can be printed: - within bounds ∨ - ∨ escape sequence ∨ - ∨ last with printed ∧ not first byte in character */ - (col < width) || - (esc != 0) || - (ok && ((b & 0xC0) == 0x80))) - { - printf("%c", b); - if ((esc == 0) && ((b & 0xC0) != 0x80)) - /* Count up columns of not in escape sequnce and */ - col++; /* the byte is not the first byte in the character */ - ok = true; - } - else - ok = false; - - if (esc == 10) - esc = 0; -} - -/* Converts a string to an integer - * - * @param string The string to convert - * @return The integer represented by the string - */ -int toInt(String string) -{ - int rc = 0; - String str = string; - char c = 0; - - while ((c = *str++) != 0) - rc = (rc << 1) + (rc << 3) - (c & 15); - - return -rc; -} diff --git a/pq4ps b/pq4ps index 433f062..ace4a30 100755 --- a/pq4ps +++ b/pq4ps @@ -1,15 +1,17 @@ #!/bin/bash +INSTALLDIR="$(dirname "$(dirname "$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )")")" # Get main bash script directory's parent + if [[ $# == 1 ]] && [[ "$1" == '-l' || "$1" == '--list' ]]; then - perl $0.pl | cut -d @ -f 1 | uniq + perl "$0.pl" "$INSTALLDIR" | cut -d @ -f 1 | uniq else - _ponies="$(perl $0.pl)" + _ponies="$(perl "$0.pl" "$INSTALLDIR")" ponies=() - if [[ ! $# == 0 ]]; then - p="" + if (( $# > 1 )); then + p=() for arg in "$@"; do - p=$p$(echo "$_ponies" | grep "^$arg@")" " + p+=( $(echo "$_ponies" | grep "^$arg@") ) done _ponies=$p fi @@ -32,7 +34,7 @@ else p="$(echo $pony | cut -d '@' -f 1)" f="$(echo $pony | cut -d '@' -f 2)" - q="$(cat "/usr/share/ponysay/quotes/$f")" + q="$(cat "$INSTALLDIR/share/ponysay/quotes/$f")" echo "-f" $p $q fi diff --git a/pq4ps-list b/pq4ps-list index 4a082fe..8febce4 100755 --- a/pq4ps-list +++ b/pq4ps-list @@ -1,6 +1,6 @@ #!/bin/bash -cmd=$(echo $0 | sed -e 's/\-list$//g') -pl=$0.pl +cmd="$(echo "$0" | sed -e 's/\-list$//g')" +pl="$0.pl" -bash -c "$($pl $($cmd --list))" +bash -c "$("$pl" $($cmd --list))" diff --git a/pq4ps.pl b/pq4ps.pl index a10c998..2f45053 100755 --- a/pq4ps.pl +++ b/pq4ps.pl @@ -1,9 +1,9 @@ #!/usr/bin/perl -opendir(DIR, "/usr/share/ponysay/ponies/"); +opendir(DIR, $ARGV[0]."/share/ponysay/ponies/"); @files = readdir(DIR); -opendir(DIR, "/usr/share/ponysay/quotes/"); +opendir(DIR, $ARGV[0]."/share/ponysay/quotes/"); @quotes = readdir(DIR); diff --git a/share/ponysay/ponies b/share/ponysay/ponies new file mode 120000 index 0000000..2852287 --- /dev/null +++ b/share/ponysay/ponies @@ -0,0 +1 @@ +../../ponies/ \ No newline at end of file diff --git a/share/ponysay/quotes b/share/ponysay/quotes new file mode 120000 index 0000000..3203ed3 --- /dev/null +++ b/share/ponysay/quotes @@ -0,0 +1 @@ +../../quotes/ \ No newline at end of file diff --git a/share/ponysay/ttyponies b/share/ponysay/ttyponies new file mode 120000 index 0000000..7824083 --- /dev/null +++ b/share/ponysay/ttyponies @@ -0,0 +1 @@ +../../ttyponies/ \ No newline at end of file diff --git a/truncater.c b/truncater.c new file mode 100644 index 0000000..d703406 --- /dev/null +++ b/truncater.c @@ -0,0 +1,153 @@ +/* ponysaytruncater + * Output truncater used by ponysay to stop + * large ponies from being printed badly. + * + * Licensed under WTFPL + * See COPYING for details + */ +#include +#define String char* +#define boolean char +#define true 1 +#define false 0 + +/* Stdin file descriptor ID */ +#define STDIN 0 + +/* The number of columns on the current line */ +static int col = 0; + +/* Escape sequence state */ +static int esc = 0; + +/* Last bytes as written */ +static boolean ok = true; + +void write(char b, int width); +int toInt(String string); + + +/* Mane method! + * The only argument, in addition to the executed file, + * should be the width of the terminal which you get by + * adding `tput cols || echo 0` as an argument. + * + * @param argc The number of startup arguments + * @param argv The startup arguments, the first is the file itself + * + * @author Mattias Andrée, maandree@kth.se + */ +void main(int argc, String* argv) +{ + int width = 0; + if (argc > 1) + width = toInt(*(argv + 1)); + + char b = 0; + + if (width > 15) /* sanity */ + while (read(STDIN, &b, 1)) + write(b, width); + else + while (read(STDIN, &b, 1)) + printf("%c", b); +} + +/* Writes a character to stdout, iff it fits within the terminal + * + * @param b The character (byte) to write + * @param width The width of the terminal + */ +void write(char b, int width) +{ + int i; + char tabstop; + + if (esc == 0) + { + if (b == '\n') + { + if (col >= width) + { + /* Reset background colour */ + write('\e', width); + write('[', width); + write('4', width); + write('9', width); + write('m', width); + } + col = -1; + } + else if (b == '\t') + { + /* Tab to next pos ≡₈ 0 */ + tabstop = 8 - (col & 7); + for (i = 0; i < tabstop; i++) + write(' ', width); + return; /* (!) */ + } + else if (b == '\e') + esc = 1; + } + else if (esc == 1) + { + if (b == '[') esc = 2; /* CSI: CSI ends with a letter, m is for colour */ + else if (b == ']') esc = 3; /* OSI: OSI P is for palette editing in Linux VT */ + else esc = 10; /* Nothing to see here, move along */ + } + else if (esc == 2) + { + if ((('a' <= b) && (b <= 'z')) || (('A' <= b) && (b <= 'Z'))) + esc = 10; + } + else if ((esc == 3) && (b == 'P')) + { + esc = ~0; + } + else if (esc < 0) + { + esc--; + if (esc == ~7) + esc = 10; + } + else + esc = 10; + + if ( + /* Can be printed: + within bounds ∨ + ∨ escape sequence ∨ + ∨ last with printed ∧ not first byte in character */ + (col < width) || + (esc != 0) || + (ok && ((b & 0xC0) == 0x80))) + { + printf("%c", b); + if ((esc == 0) && ((b & 0xC0) != 0x80)) + /* Count up columns of not in escape sequnce and */ + col++; /* the byte is not the first byte in the character */ + ok = true; + } + else + ok = false; + + if (esc == 10) + esc = 0; +} + +/* Converts a string to an integer + * + * @param string The string to convert + * @return The integer represented by the string + */ +int toInt(String string) +{ + int rc = 0; + String str = string; + char c = 0; + + while ((c = *str++) != 0) + rc = (rc << 1) + (rc << 3) - (c & 15); + + return -rc; +} diff --git a/ttyponies/elsie.pony b/ttyponies/elsie.pony new file mode 120000 index 0000000..acc1800 --- /dev/null +++ b/ttyponies/elsie.pony @@ -0,0 +1 @@ +./prettyvision.pony \ No newline at end of file -- cgit