From 8d4e353c66b5ab380c28ce78d3126ca47867eada Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 10 Dec 2019 13:01:32 -0800 Subject: [PATCH] Update taskme, don't quote builtins and &, &&. If the command is an executable, you can have quotes around it. But if it is a builtin like `copy` then quotes will break it. So let's remove quotes from the command as long as it doesn't have spaces. Also remove quotes from & and && because with quotes you can't actually chain commands. However if you want to literally use & as an arg then this may cause some problems. --- taskme.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/taskme.py b/taskme.py index 3605d33..8fe151f 100644 --- a/taskme.py +++ b/taskme.py @@ -12,11 +12,21 @@ import os if len(sys.argv) < 2: raise ValueError() -task_command = ' '.join('"%s"' % arg for arg in sys.argv[1:]) -task_command = f'cd /d {os.getcwd()} & {task_command}' +task_line = sys.argv[1:] +task_command = task_line[0] +if ' ' in task_command: + task_command = '"%s"' % task_command +task_arguments = task_line[1:] +for (index, arg) in enumerate(task_arguments): + if arg not in ['&', '&&']: + task_arguments[index] = '"%s"' % arg +task_arguments = ' '.join(task_arguments) -timestamp = f'{time.time()}'.replace('.', '').ljust(18, '0') -filename = f'C:\\tasks\\{timestamp}-{random.randint(1, 1000000)}.task' +task_command = f'cd /d "{os.getcwd()}" & {task_command} {task_arguments}' + +timestamp = f'{time.time():<019}'.replace('.', '') +randid = f'{random.randint(1, 1000000):>06}' +filename = f'C:\\tasks\\{timestamp}-{randid}.task' with open(filename, 'w', encoding='utf-8') as handle: handle.write(task_command)