mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-09-03 23:57:17 -04:00
Add port-job for making clipclear.py platform-specific
Former-commit-id: 6aafd4dfcddefc31bf61d3018b63ef48c156d8a8 Former-commit-id: c016e6872d71bc4bb347d85cf964dd9e7b7fe149
This commit is contained in:
+4
-3
@@ -6,12 +6,12 @@ from time import sleep
|
|||||||
|
|
||||||
# set period of time to wait before attempting to clear clipboard
|
# set period of time to wait before attempting to clear clipboard
|
||||||
sleep(30)
|
sleep(30)
|
||||||
|
# enable the storing of clipboard contents hash for later comparison
|
||||||
# store a hash of the current clipboard contents for later comparison
|
|
||||||
_hash_paste = sha512()
|
_hash_paste = sha512()
|
||||||
|
|
||||||
|
# PORT START CLIPCLEAR
|
||||||
if argv[2] == 'wsl':
|
if argv[2] == 'wsl':
|
||||||
_hash_paste.update(run(('powershell.exe', '-c', 'Get-Clipboard'), stdout=PIPE).stdout.strip())
|
_hash_paste.update(run(('powershell.exe', '-c', 'Get-Clipboard'), stdout=PIPE).stdout.strip())
|
||||||
# if the supplied hash matches the hash of the current clipboard contents, clear the clipboard
|
|
||||||
if argv[1] == _hash_paste.hexdigest():
|
if argv[1] == _hash_paste.hexdigest():
|
||||||
run(('powershell.exe', '-c', 'Set-Clipboard'))
|
run(('powershell.exe', '-c', 'Set-Clipboard'))
|
||||||
|
|
||||||
@@ -39,3 +39,4 @@ elif argv[2] == 'x11':
|
|||||||
_hash_paste.update(run(('xclip', '-o', '-sel', 'c'), stdout=PIPE).stdout.strip())
|
_hash_paste.update(run(('xclip', '-o', '-sel', 'c'), stdout=PIPE).stdout.strip())
|
||||||
if argv[1] == _hash_paste.hexdigest():
|
if argv[1] == _hash_paste.hexdigest():
|
||||||
run(('xclip', '-i', '/dev/null', '-sel', 'c'))
|
run(('xclip', '-i', '/dev/null', '-sel', 'c'))
|
||||||
|
# PORT END CLIPCLEAR
|
||||||
|
|||||||
+36
-18
@@ -3,42 +3,60 @@ import re
|
|||||||
from sys import argv, exit as s_exit
|
from sys import argv, exit as s_exit
|
||||||
|
|
||||||
# read arguments
|
# read arguments
|
||||||
arguments, replacement = argv[1:], None
|
arguments, clip_replacement, clear_replacement = argv[1:], None, None
|
||||||
|
|
||||||
# define replacement text depending on arguments
|
# define replacement text depending on arguments
|
||||||
if len(arguments) > 0:
|
if len(arguments) > 0:
|
||||||
if arguments[0] == 'WSL':
|
if arguments[0] == 'WSL':
|
||||||
replacement = """run(('powershell.exe', '-c', "Set-Clipboard '" + _copy_subject.replace("'", "''") + "'"))
|
clip_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)"""
|
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'wsl'), stdout=DEVNULL, stderr=DEVNULL)"""
|
||||||
|
clear_replacement = """_hash_paste.update(run(('powershell.exe', '-c', 'Get-Clipboard'), stdout=PIPE).stdout.strip())
|
||||||
|
if argv[1] == _hash_paste.hexdigest():
|
||||||
|
run(('powershell.exe', '-c', 'Set-Clipboard'))"""
|
||||||
elif arguments[0] == 'MAC':
|
elif arguments[0] == 'MAC':
|
||||||
replacement = """run('pbcopy', stdin=Popen(('printf', '%b', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')), stdout=PIPE).stdout)
|
clip_replacement = """run('pbcopy', stdin=Popen(('printf', '%b', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')), stdout=PIPE).stdout)
|
||||||
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'mac'))"""
|
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'mac'))"""
|
||||||
|
clear_replacement = """_hash_paste.update(run(('pbpaste'), stdout=PIPE).stdout.strip())
|
||||||
|
if argv[1] == _hash_paste.hexdigest():
|
||||||
|
run('pbcopy', input=b'')"""
|
||||||
elif arguments[0] == 'HAIKU':
|
elif arguments[0] == 'HAIKU':
|
||||||
replacement = """run(('clipboard', '-c', _copy_subject))
|
clip_replacement = """run(('clipboard', '-c', _copy_subject))
|
||||||
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'haiku'))"""
|
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'haiku'))"""
|
||||||
|
clear_replacement = """_hash_paste.update(run(('clipboard', '-p'), stdout=PIPE).stdout.strip())
|
||||||
|
if argv[1] == _hash_paste.hexdigest():
|
||||||
|
run(('clipboard', '-r'))"""
|
||||||
elif arguments[0] == 'TERMUX':
|
elif arguments[0] == 'TERMUX':
|
||||||
replacement = """run(('termux-clipboard-set', _copy_subject))
|
clip_replacement = """run(('termux-clipboard-set', _copy_subject))
|
||||||
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'termux'))"""
|
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'termux'))"""
|
||||||
|
clear_replacement = """_hash_paste.update(run(('termux-clipboard-get'), stdout=PIPE).stdout.strip())
|
||||||
|
if argv[1] == _hash_paste.hexdigest():
|
||||||
|
run(("termux-clipboard-set", "''"))"""
|
||||||
elif arguments[0] in ('LINUX', 'BSD'):
|
elif arguments[0] in ('LINUX', 'BSD'):
|
||||||
replacement = """if 'WAYLAND_DISPLAY' in environ:
|
clip_replacement = """if 'WAYLAND_DISPLAY' in environ:
|
||||||
run('wl-copy', stdin=Popen(('printf', '%b', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')), stdout=PIPE).stdout)
|
run('wl-copy', stdin=Popen(('printf', '%b', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')), stdout=PIPE).stdout)
|
||||||
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'wayland'))
|
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'wayland'))
|
||||||
else:
|
else:
|
||||||
run(('xclip', '-sel', 'c'), stdin=Popen(('printf', '%b', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')), stdout=PIPE).stdout)
|
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'))"""
|
Popen((realpath(__file__).rsplit('/', 1)[0] + "/clipclear.py", _hash.hexdigest(), 'x11'))"""
|
||||||
|
clear_replacement = """if argv[2] == 'wayland':
|
||||||
|
_hash_paste.update(run('wl-paste', stdout=PIPE).stdout.strip())
|
||||||
|
if argv[1] == _hash_paste.hexdigest():
|
||||||
|
run(('wl-copy', '-c'))
|
||||||
|
else
|
||||||
|
_hash_paste.update(run(('xclip', '-o', '-sel', 'c'), stdout=PIPE).stdout.strip())
|
||||||
|
if argv[1] == _hash_paste.hexdigest():
|
||||||
|
run(('xclip', '-i', '/dev/null', '-sel', 'c'))"""
|
||||||
else:
|
else:
|
||||||
s_exit()
|
s_exit()
|
||||||
|
|
||||||
# define PORT target
|
targets = (('CLIPBOARD', 'sshyp.py', '', '', clip_replacement),
|
||||||
string1 = '# PORT START CLIPBOARD'
|
('CLIPCLEAR', 'clipclear.py', '\n', '', clear_replacement))
|
||||||
string2 = '# PORT END CLIPBOARD'
|
|
||||||
|
|
||||||
# read input file
|
for target in targets:
|
||||||
text = open('working/sshyp.py', 'r').read()
|
# read text from target file
|
||||||
|
text = open(f"working/{target[1]}", 'r').read()
|
||||||
# find and replace the defined PORT target
|
# compile regex and modify text
|
||||||
regex = re.compile(f"{string1}.*?{string2}", re.DOTALL)
|
regex = re.compile(f"{target[2]}# PORT START {target[0]}.*?# PORT END {target[0]}{target[3]}", re.DOTALL)
|
||||||
new_text = re.sub(regex, replacement, text)
|
new_text = re.sub(regex, target[4], text)
|
||||||
|
# write updated text to target file
|
||||||
# write updated text
|
open(f"working/{target[1]}", 'w').write(new_text)
|
||||||
open('working/sshyp.py', 'w').write(new_text)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user