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.
This commit is contained in:
voussoir 2019-12-10 13:01:32 -08:00
parent e99cbe3e39
commit 8d4e353c66

View file

@ -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)