Title: Set-Clipboard -Remote with OSC52 · Issue #18116 · PowerShell/PowerShell · GitHub
Open Graph Title: Set-Clipboard -Remote with OSC52 · Issue #18116 · PowerShell/PowerShell
X Title: Set-Clipboard -Remote with OSC52 · Issue #18116 · PowerShell/PowerShell
Description: Summary of the new feature / enhancement Set-Clipboard does not really work over SSH, as it always sets the clipboard of the target machine, not the host. This means that if you SSH e.g. from your PC to a server, then Set-Clipboard will ...
Open Graph Description: Summary of the new feature / enhancement Set-Clipboard does not really work over SSH, as it always sets the clipboard of the target machine, not the host. This means that if you SSH e.g. from your ...
X Description: Summary of the new feature / enhancement Set-Clipboard does not really work over SSH, as it always sets the clipboard of the target machine, not the host. This means that if you SSH e.g. from your ...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/18116
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Set-Clipboard -Remote with OSC52","articleBody":"### Summary of the new feature / enhancement\n\n`Set-Clipboard` does not really work over SSH, as it always sets the clipboard of the target machine, not the host. This means that if you SSH e.g. from your PC to a server, then `Set-Clipboard` will set the server's clipboard, not your PCs, so you cannot paste it anywhere.\r\n\r\nThis can be resolved by using ANSI escape sequence (same mechanism as for setting colors) [OSC52](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands:~:text=Ps%20%3D%205%202%20%20%E2%87%92%C2%A0%20Manipulate%20Selection%20Data), which sets the clipboard of the host machine, which in our example is the PC, so you can paste it anywhere. This sequence is supported by most terminals, including [Microsoft Terminal](https://github.com/microsoft/terminal/issues/2946).\r\n\r\nExample:\r\n```pwsh\r\nfunction Set-RemoteClipboard($text) {\r\n Write-Host \"`e]52;;$([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($text)))`a\"\r\n}\r\n# Copy \"original\" into a clipboard from anywhere\r\n\u003e Set-Clipboard 'changed'\r\n# Press Ctrl+Shift+V to see clipboard still \"original\"\r\n\u003e Set-RemoteClipboard 'changed'\r\n# Press Ctrl+Shift+V to see clipboard now \"changed\"\r\n```\r\n\r\nOSC also has similar `Get-Clipboard -Remote` sequence, but no terminal implements it as it is rightly considered a security and privacy risk, and you ca simply \"get\" the host clipboard with Ctrl+Shift+V.\r\n\r\nOpens:\r\n1. Should we autodetect when to use the OSC52 instead of xclip or other OS target-implementation? E.g. SSH can be detected by presence of environment variables `$env:SSH_CLIENT` and `$env:SSH_TTY`. I would say no, as it could be potentially breaking behavior in case of false positives on terminals which don't support the OSC. If user wants such behavior, they can add `$PSDefaultParameters['Set-Clipboard:Remote'] = $env:SSH_CLIENT -or $env:SSH_TTY` to their `$PROFILE`.\r\n2. Some terminal multiplexers like screen and tmux may require wrapping OSC52 into a different escape, as can be seen in the [vim plugin implementation](https://github.com/ojroques/vim-oscyank/blob/main/plugin/oscyank.vim). Should we detect and handle those cases? tmux can be forced to work with default escape by setting `set -s set-clipboard on`. I would say keep it simple for now, then maybe add `-RemoteMethod = auto | osc52 | tmux | screen` in separate issue if required.\n\n### Proposed technical implementation details (optional)\n\nSee example for the escape sequence format.","author":{"url":"https://github.com/dkaszews","@type":"Person","name":"dkaszews"},"datePublished":"2022-09-17T10:23:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/18116/PowerShell/issues/18116"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2db59f26-4d2e-3ba4-4bdf-1cc88674480d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C3A0:3102C2:DA3756:126BC1A:6A543CE9 |
| html-safe-nonce | f2db15c69340a151df5a45895ea9bbe0e3b11f4a3c261d875bdfdb2aab39be57 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDM0EwOjMxMDJDMjpEQTM3NTY6MTI2QkMxQTo2QTU0M0NFOSIsInZpc2l0b3JfaWQiOiI3NzAxNDc5MTg3OTQxNzAyODg5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 77da42422dcb579301e8f454143af29f85a21acd3866143c128822bcc28df091 |
| hovercard-subject-tag | issue:1376732618 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/18116/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0a7f8afb96281bbefd8d925b77996bc4ad107fab677a4e98629b5ce9bdec6027/PowerShell/PowerShell/issues/18116 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0a7f8afb96281bbefd8d925b77996bc4ad107fab677a4e98629b5ce9bdec6027/PowerShell/PowerShell/issues/18116 |
| og:image:alt | Summary of the new feature / enhancement Set-Clipboard does not really work over SSH, as it always sets the clipboard of the target machine, not the host. This means that if you SSH e.g. from your ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dkaszews |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width