Add copy command for clipboard integration
#910
+335
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a new
copycommand to PsySH, allowing users to copy the inspected value of an expression or the last evaluated result ($_) directly to the system clipboard. This feature is inspired by the clipboard integration recently implemented in Ruby's IRB (ruby/irb#1044).To ensure a seamless experience across various environments, the command automatically detects and utilizes available clipboard backends, including:
pbcopy(macOS)wl-copy(Wayland / WSLg)xclip/xsel(X11)clip.exe(Windows / WSL)Furthermore, I have implemented support for the OSC 52 escape sequence to facilitate remote development over SSH. This allows PsySH to bridge the remote server's output to the local machine's clipboard. OSC 52 is increasingly adopted by modern terminal emulators, including Windows Terminal and Ghostty, both of which prioritize security while enabling this functionality.
Since OSC 52 enables a remote process to write to the local terminal, this functionality is strictly opt-in via the new
useOsc52Clipboardconfiguration. This approach mirrors the security-conscious defaults of terminals like Ghostty, where clipboard access must be explicitly allowed. When the command is used in an SSH environment without this setting enabled, PsySH will display a helpful "Productivity Tip" on how to enable it, along with a clear security warning regarding the risks of clipboard hijacking.