mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-09-06 09:07:13 -04:00
Initial addition of #20 (ports framework), clipboard port-job
Former-commit-id: 2b6a931b1ae67e645a1f5dbf1b7ce51cf7c837ba Former-commit-id: 04fffa7119d954f2c4cf41fdac01782306d888de
This commit is contained in:
Executable
+49
@@ -0,0 +1,49 @@
|
||||
#!/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 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)"""
|
||||
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 the updated text
|
||||
open("working/sshyp.py", "w").write(new_text)
|
||||
Reference in New Issue
Block a user