From 62a3d88d58bc5be870587012d74e28d57529356e Mon Sep 17 00:00:00 2001 From: Elis Axelsson Date: Sat, 18 Aug 2012 20:10:46 +0200 Subject: Check if script is being launched in subshell or being redirected to file, and make -l to --onelist. This more or less depricates '--onelist' as flag --- ponysay.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'ponysay.py') diff --git a/ponysay.py b/ponysay.py index 800343e..dcfb6b0 100755 --- a/ponysay.py +++ b/ponysay.py @@ -46,6 +46,12 @@ Whether the program is execute in Linux VT (TTY) linuxvt = os.environ['TERM'] == 'linux' +''' +Whether the program is launched in subshell/beeing redirected +''' +redirected = not sys.stdout.isatty() + + ''' The directories where pony files are stored, ttyponies/ are used if the terminal is Linux VT (also known as TTY) ''' @@ -81,7 +87,7 @@ parser.add_argument( '--onelist', action = 'store_true', dest = 'onelist', parser.add_argument('-W', '--wrap', action = 'store', dest = 'wrap', help = 'specify the column when the message should be wrapped') parser.add_argument('-f', '--pony', action = 'append', dest = 'pony', help = 'select a pony (either a file name or a pony name)') parser.add_argument('-q', '--quote', nargs = '*', dest = 'quote', help = 'select a pony which will quote herself') -parser.add_argument('message', nargs = '?', help = 'message to ponysay') +parser.add_argument('message', nargs = '?', help = 'message to ponysay') args = parser.parse_args() # TODO implement if [ -t 0 ] && [ $# == 0 ]; then @@ -99,6 +105,10 @@ class ponysay(): Starts the part of the program the arguments indicate ''' def __init__(self, args): + if args.list and redirected: + args.list = False + args.onelist = True + if args.list: self.list() elif args.linklist: self.linklist() elif args.quoters: self.quoters() -- cgit