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)