mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-08-28 04:46:34 -04:00
(WSL) Port new clipboard clear behavior to WSL
Former-commit-id: e1d96418abae79f6af75d72eeb6279e661196bd5 Former-commit-id: 0b345de72d9dc13de2f0db7c26264e0deb685965
This commit is contained in:
+6
-3
@@ -542,18 +542,21 @@ def copy_data():
|
||||
# store hashed _copy_subject for later comparison
|
||||
_hash = sha512()
|
||||
_hash.update(_copy_subject.encode('utf-8'))
|
||||
_hash = _hash.hexdigest() + f"{2*' '}-"
|
||||
|
||||
# PORT START CLIPBOARD
|
||||
# WSL clipboard detection
|
||||
if 'WSL_DISTRO_NAME' in environ:
|
||||
run(('powershell.exe', '-c', "Set-Clipboard '" + _copy_subject.replace("'", "''") + "'"))
|
||||
Popen("sleep 30; powershell.exe -c Set-Clipboard ''", shell=True, stdout=DEVNULL, stderr=DEVNULL)
|
||||
Popen("sleep 30; temp=$(echo \"$(powershell.exe -Command \'Get-FileHash -InputStream $([IO.MemoryStream]"
|
||||
"::new([byte[]][char[]]\"$(Get-Clipboard)\")) -Algorithm SHA512 | Select-Object -ExpandProperty "
|
||||
f"Hash\')\" | dos2unix); test \'{_hash.hexdigest().upper()}\' = \"$temp\" && powershell.exe -c "
|
||||
"Set-Clipboard", shell=True, stdout=DEVNULL, stderr=DEVNULL)
|
||||
# Wayland clipboard detection
|
||||
elif 'WAYLAND_DISPLAY' in environ:
|
||||
run('wl-copy', stdin=Popen(('printf', _copy_subject.replace('\\', '\\\\').replace('%', '%%')),
|
||||
stdout=PIPE).stdout)
|
||||
Popen(f"sleep 30; test \'{_hash}\' = \"$(printf \"$(wl-paste)\" | sha512sum)\" && wl-copy -c", shell=True)
|
||||
Popen(f"sleep 30; test \'{_hash.hexdigest() + 2*' ' + '-'}\' = \"$(printf \"$(wl-paste)\" | sha512sum)\" "
|
||||
"&& wl-copy -c", shell=True)
|
||||
# Haiku clipboard detection
|
||||
elif uname()[0] == 'Haiku':
|
||||
run(('clipboard', '-c', _copy_subject))
|
||||
|
||||
@@ -9,7 +9,10 @@ arguments, replacement = argv[1:], None
|
||||
if len(arguments) > 0:
|
||||
if arguments[0] == 'WSL':
|
||||
replacement = """run(('powershell.exe', '-c', "Set-Clipboard '" + _copy_subject.replace("'", "''") + "'"))
|
||||
Popen("sleep 30; powershell.exe -c Set-Clipboard ''", shell=True, stdout=DEVNULL, stderr=DEVNULL)"""
|
||||
Popen("sleep 30; temp=$(echo \\"$(powershell.exe -Command \\'Get-FileHash -InputStream $([IO.MemoryStream]"
|
||||
"::new([byte[]][char[]]\\"$(Get-Clipboard)\\")) -Algorithm SHA512 | Select-Object -ExpandProperty "
|
||||
f"Hash\\')\\" | dos2unix); test \\'{_hash.hexdigest().upper()}\\' = \\"$temp\\" && powershell.exe -c "
|
||||
"Set-Clipboard", shell=True, stdout=DEVNULL, stderr=DEVNULL)"""
|
||||
elif arguments[0] == 'MAC':
|
||||
replacement = """run('pbcopy', stdin=Popen(('printf', _copy_subject.replace('\\\\\\', '\\\\\\\\\\\\\\')
|
||||
.replace('%', '%%')), stdout=PIPE).stdout)
|
||||
@@ -24,7 +27,8 @@ if len(arguments) > 0:
|
||||
replacement = """if 'WAYLAND_DISPLAY' in environ:
|
||||
run('wl-copy', stdin=Popen(('printf', _copy_subject
|
||||
.replace('\\\\\\', '\\\\\\\\\\\\\\').replace('%', '%%')), stdout=PIPE).stdout)
|
||||
Popen(f"sleep 30; test \\'{_hash}\\' = \\"$(printf \\"$(wl-paste)\\" | sha512sum)\\" && wl-copy -c", shell=True)
|
||||
Popen(f"sleep 30; test \\'{_hash.hexdigest() + 2*' ' + '-'}\\' = \\"$(printf \\"$(wl-paste)\\" | sha512sum)\\" "
|
||||
"&& wl-copy -c", shell=True)
|
||||
else:
|
||||
run(('xclip', '-sel', 'c'), stdin=Popen(('printf', _copy_subject
|
||||
.replace('\\\\\\', '\\\\\\\\\\\\\\').replace('%', '%%')), stdout=PIPE).stdout)
|
||||
|
||||
Reference in New Issue
Block a user