coder / code-server

VS Code in the browser
https://coder.com
MIT License
66.47k stars 5.45k forks source link

clipboard support: code-server --stdin-to-clipboard #6807

Closed smerschjohann closed 1 month ago

smerschjohann commented 1 month ago

This PR adds support for pasting to clipboard from STDIN. This is especially useful from the integrated terminal.

Use like this:

# directly from the integrated terminal
echo -n "HELLO CODE-SERVER!" | code-server --stdin-to-clipboard

# as an alias
alias xclip="code-server --stdin-to-clipboard"
echo -n "HELLO FROM ALIAS!" | xclip

# or from an executable
sudo tee /usr/local/bin/xclip << EOF
#!/bin/sh
code-server --stdin-to-clipboard
EOF
sudo chmod +x /usr/local/bin/xclip
echo -n "HELLO FROM executable!" | xclip

Fixes #6175

smerschjohann commented 1 month ago

Yeah, it kind of is ;)

From terminal to "remote cli", from there via a Unix socket to code-server. Then it uses the general clipboard service which passes it to the Browser clipboard API. This approves the request because the browser window is in focus. Finally, the data is sent to the local clipboard.

A lot of steps but works nicely. :+1: