mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-09-01 14:47:17 -04:00
Former-commit-id: 8ecbbb6199864fda973e47605a10d737318f3993 Former-commit-id: eb625eded3f9518967ee9fa06201311e8571e394
45 lines
2.1 KiB
Python
Executable File
45 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import re
|
|
from sys import argv, exit as s_exit
|
|
|
|
# read arguments
|
|
arguments, replacement = argv[1:], None
|
|
|
|
# define replacement text depending on arguments
|
|
if len(arguments) > 0:
|
|
if arguments[0] == 'WSL':
|
|
replacement = """run(('powershell.exe', '-c', "Set-Clipboard '" + _copy_subject.replace("'", "''") + "'"))
|
|
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'wsl'), stdout=DEVNULL, stderr=DEVNULL)"""
|
|
elif arguments[0] == 'MAC':
|
|
replacement = """run('pbcopy', stdin=Popen(('printf', '%b', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')), stdout=PIPE).stdout)
|
|
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'mac'))"""
|
|
elif arguments[0] == 'HAIKU':
|
|
replacement = """run(('clipboard', '-c', _copy_subject))
|
|
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'haiku'))"""
|
|
elif arguments[0] == 'TERMUX':
|
|
replacement = """run(('termux-clipboard-set', _copy_subject))
|
|
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'termux'))"""
|
|
elif arguments[0] in ('LINUX', 'BSD'):
|
|
replacement = """if 'WAYLAND_DISPLAY' in environ:
|
|
run('wl-copy', stdin=Popen(('printf', '%b', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')), stdout=PIPE).stdout)
|
|
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'wayland'))
|
|
else:
|
|
run(('xclip', '-sel', 'c'), stdin=Popen(('printf', '%b', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')), stdout=PIPE).stdout)
|
|
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'x11'))"""
|
|
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)
|