From 92f26c47aff0c359bf82e5d27533094a1f0b9285 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Fri, 14 Apr 2023 12:50:49 -0400 Subject: [PATCH] port-jobs: Added default behavior for port-jobs if no argument is supplied Former-commit-id: 0af03c8af7101fead7de41f2f644ea80c38a5392 Former-commit-id: 1f9607f85ca9d1cf786741a34124eda589f3dd95 --- port-jobs/CLIPBOARD.py | 47 +++++++++++++++++++++--------------------- port-jobs/COMMENTS.py | 2 +- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/port-jobs/CLIPBOARD.py b/port-jobs/CLIPBOARD.py index 5bace3d..e559662 100755 --- a/port-jobs/CLIPBOARD.py +++ b/port-jobs/CLIPBOARD.py @@ -6,31 +6,32 @@ from sys import argv, exit as s_exit arguments = argv[1:] # define replacement text depending on arguments -if arguments[0] == 'WSL': - replacement = """run(['pwsh.exe', '-c', 'Set-Clipboard', _copy_line[_index].rstrip()]) - Popen("sleep 30; pwsh.exe -c 'echo \\"\\" | Set-Clipboard'", shell=True)""" -elif arguments[0] == 'MAC': - replacement = """run(['pbcopy'], stdin=Popen(['printf', _copy_line[_index].rstrip().replace('\\\\\\', '\\\\\\\\\\\\\\').replace('%', '%%')], - stdout=PIPE).stdout) - Popen("sleep 30; printf '' | pbcopy", shell=True)""" -elif arguments[0] == 'HAIKU': - replacement = """run(['clipboard', '-c', _copy_line[_index].rstrip()]) - Popen('sleep 30; clipboard -r', shell=True)""" -elif arguments[0] == 'TERMUX': - replacement = """run(['termux-clipboard-set', _copy_line[_index].rstrip()]) - Popen("sleep 30; termux-clipboard-set ''", shell=True)""" -elif arguments[0] == 'BSD': - replacement = """run(['xclip', '-sel', 'c'], stdin=Popen(['printf', _copy_line[_index].rstrip().replace('\\\\\\', '\\\\\\\\\\\\\\') +if len(arguments) > 0: + if arguments[0] == 'WSL': + replacement = """run(['pwsh.exe', '-c', 'Set-Clipboard', _copy_line[_index].rstrip()]) + Popen("sleep 30; pwsh.exe -c 'echo \\"\\" | Set-Clipboard'", shell=True)""" + elif arguments[0] == 'MAC': + replacement = """run(['pbcopy'], stdin=Popen(['printf', _copy_line[_index].rstrip().replace('\\\\\\', '\\\\\\\\\\\\\\').replace('%', '%%')], + stdout=PIPE).stdout) + Popen("sleep 30; printf '' | pbcopy", shell=True)""" + elif arguments[0] == 'HAIKU': + replacement = """run(['clipboard', '-c', _copy_line[_index].rstrip()]) + Popen('sleep 30; clipboard -r', shell=True)""" + elif arguments[0] == 'TERMUX': + replacement = """run(['termux-clipboard-set', _copy_line[_index].rstrip()]) + Popen("sleep 30; termux-clipboard-set ''", shell=True)""" + elif arguments[0] == 'BSD': + replacement = """run(['xclip', '-sel', 'c'], stdin=Popen(['printf', _copy_line[_index].rstrip().replace('\\', '\\\\') .replace('%', '%%')], stdout=PIPE).stdout) Popen("sleep 30; printf '' | xclip -sel c", shell=True)""" -elif arguments[0] == 'LINUX': - replacement = """if 'WAYLAND_DISPLAY' in environ: # Wayland clipboard detection - run(['wl-copy', _copy_line[_index].rstrip()]) - Popen('sleep 30; wl-copy -c', shell=True) - else: # X11 clipboard detection - run(['xclip', '-sel', 'c'], stdin=Popen(['printf', _copy_line[_index].rstrip().replace('\\\\\\', '\\\\\\\\\\\\\\') - .replace('%', '%%')], stdout=PIPE).stdout) - Popen("sleep 30; printf '' | xclip -sel c", shell=True)""" + elif arguments[0] == 'LINUX': + replacement = """if 'WAYLAND_DISPLAY' in environ: # Wayland clipboard detection + run(['wl-copy', _copy_line[_index].rstrip()]) + Popen('sleep 30; wl-copy -c', shell=True) + else: # X11 clipboard detection + run(['xclip', '-sel', 'c'], stdin=Popen(['printf', _copy_line[_index].rstrip().replace('\\\\\\', '\\\\\\\\\\\\\\') + .replace('%', '%%')], stdout=PIPE).stdout) + Popen("sleep 30; printf '' | xclip -sel c", shell=True)""" else: s_exit() diff --git a/port-jobs/COMMENTS.py b/port-jobs/COMMENTS.py index cbfb539..36c57a5 100755 --- a/port-jobs/COMMENTS.py +++ b/port-jobs/COMMENTS.py @@ -6,7 +6,7 @@ from sys import argv arguments = argv[1:] # define regular expression depending on arguments -if arguments[0] == 'ALL': +if len(arguments) > 0 and arguments[0] == 'ALL': regex = re.compile(r'^\s*#.*$\n?', re.MULTILINE) else: regex = re.compile(r'^\s*# PORT.*$\n?', re.MULTILINE)