diff options
author | Mattias Andrée <maandree@operamail.com> | 2012-08-18 19:27:59 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2012-08-18 19:27:59 +0200 |
commit | ee3c5532b8e0330b7bbed6d013489cbb4748a0ca (patch) | |
tree | bc0677d1bcfc1b3876974569d67c69d132e248f1 | |
parent | e8864eb219201d6b3218ebf59897c942dff42f30 (diff) | |
download | ponysay-ee3c5532b8e0330b7bbed6d013489cbb4748a0ca.tar.gz ponysay-ee3c5532b8e0330b7bbed6d013489cbb4748a0ca.tar.bz2 ponysay-ee3c5532b8e0330b7bbed6d013489cbb4748a0ca.zip |
m
-rwxr-xr-x | ponysay.py | 34 | ||||
-rwxr-xr-x | ponysay.sh | 34 |
2 files changed, 30 insertions, 38 deletions
@@ -329,17 +329,17 @@ class ponysay(): ## ''' - Returns the cowsay command + Returns (the cowsay command, whether it is a custom program) ''' def __getcowsay(self): isthink = 'think.py' in __file__ if isthink: cowthink = os.environ['PONYSAY_COWTHINK'] if 'PONYSAY_COWTHINK' in os.environ else None - return 'cowthink' if (cowthink is None) or (cowthink == "") else cowthink + return ('cowthink', False) if (cowthink is None) or (cowthink == '') else (cowthink, True) cowsay = os.environ['PONYSAY_COWSAY'] if 'PONYSAY_COWSAY' in os.environ else None - return 'cowsay' if (cowsay is None) or (cowsay == "") else cowsay + return ('cowsay', False) if (cowsay is None) or (cowsay == '') else (cowsay, True) ''' @@ -352,10 +352,34 @@ class ponysay(): msg = args.message pony = self.__getponypath(args.pony) + (cowsay, customcowsay) = self.__getcowsay() + wrap_arg = ' -W ' + args.wrap if args.wrap is not None else '' + file_arg = ' -f ' + pony; + message_arg = ' \'' + msg.replace('\'', '\'\\\'\'') + '\'' # ' in message is replaces by '\'', this (combined by '..') ensures it will always be one argument + cowsay_args = wrap_arg + file_arg + message_arg if linuxvt: print('\033[H\033[2J', end='') - os.system(self.__getcowsay() + (' -W ' + args.wrap if args.wrap is not None else '') + ' -f ' + pony + ' \'' + msg.replace('\'', '\'\\\'\'') + '\'') + + if customcowsay: + exit_value = os.system(cowsay + cowsay_args) + else: + exit_value = os.system(cowsay + cowsay_args) + ## TODO not implement, but it will be obsolete if we rewrite cowsay + ''' + 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 > "/tmp/ponythink" + perl '/tmp/ponythink' "$@" + rm '/tmp/ponythink' + else + perl <(cat <(echo -e $pcmd) $ccmd) "$@" + fi + ''' + if not exit_value == 0: + sys.stderr.write('Unable to successfully execute' + (' custom ' if customcowsay else ' ') + 'cowsay [' + cowsay + ']\n') ''' @@ -383,7 +407,7 @@ class ponysay(): args.pony = [pair[0]] elif len(args.quote) == 0: sys.stderr.write('All the ponies are mute! Call the Princess!') - exit 1 + exit(1) else: args.pony = args.quote[random.randrange(0, len(args.quote))] args.message = 'I got nuthin\' good to say :(' @@ -24,27 +24,7 @@ say() { function htrunctail { tail --lines=$(( $scrh - $PONYSAY_SHELL_LINES )) } - - # Simplification of customisation of cowsay - 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 > "/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 { @@ -67,15 +47,3 @@ say() { runcmd "${wrap:+-W$wrap}" | wtrunc fi } - -# Check for cowsay -hash $cmd &>/dev/null; if [ $? -ne 0 ]; then - cat >&2 <<EOF -You don't seem to have the $cmd program. -Please install it in order to use this wrapper. - -Alternatively, symlink it to '$cmd' in anywhere in \$PATH -if it actually exists under a different filename. -EOF - exit 1 -fi |