Files
sshyp/port-jobs/CLIPBOARD.py
T
RandyTheSilly 2747aff0bf Updated port-jobs to allow for packaging the new config setup, fixed offline mode error
Former-commit-id: 511d1d887fb34b8613f063fc7992418bb614a740
Former-commit-id: 03f6817527864c52012de1d02bb2c34e8fed8a18
2023-05-13 20:48:51 -04:00

48 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python3
import re
from sys import argv, exit as s_exit
# read arguments
arguments = argv[1:]
# define replacement text depending on arguments
if len(arguments) > 0:
if arguments[0] == 'WSL':
replacement = """run(['powershell.exe', '-c', "Set-Clipboard '" + _copy_line[_index].rstrip()\
.replace("'", "''") + "'"])
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] == 'LINUX':
replacement = """if 'WAYLAND_DISPLAY' in environ:
run(['wl-copy', _copy_line[_index].rstrip()])
Popen('sleep 30; wl-copy -c', shell=True)
else:
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()
# define PORT target
string1 = '# PORT START CLIPBOARD'
string2 = '# PORT END CLIPBOARD'
# read input file
text = open('working/sshyp.py', 'r').read()
# find and replace the defined PORT target
regex = re.compile(f"{string1}.*?{string2}", re.DOTALL)
new_text = re.sub(regex, replacement, text)
# write updated text
open('working/sshyp.py', 'w').write(new_text)