| 1 | #!/usr/bin/env python3 |
| 2 | import os |
| 3 | from pathlib import Path |
| 4 | import subprocess |
| 5 | import sys |
| 6 | |
| 7 | |
| 8 | helper = str(Path(__file__).resolve().with_name("mac-agent-vm.py")) |
| 9 | if sys.argv[1:] == ["--clipboard"]: |
| 10 | with subprocess.Popen(["/usr/bin/pbpaste"], env={**os.environ, "LC_CTYPE": "en_US.UTF-8"}, stdout=subprocess.PIPE) as clipboard: |
| 11 | try: |
| 12 | result = subprocess.run( |
| 13 | [sys.executable, helper, "exec", "/usr/bin/env", "LC_CTYPE=en_US.UTF-8", "/usr/bin/pbcopy"], |
| 14 | stdin=clipboard.stdout, |
| 15 | ) |
| 16 | finally: |
| 17 | clipboard.stdout.close() |
| 18 | if clipboard.wait() or result.returncode: |
| 19 | sys.exit(1) |
| 20 | print("VM clipboard updated. Press Command-V in the VM.") |
| 21 | else: |
| 22 | os.execv(sys.executable, [sys.executable, helper, "ssh", *sys.argv[1:]]) |