1

I have some utility scripts that copy text to my clipboard using pyperclip (python library).

When I use vscode in ssh mode to develop on my remote server, I want to still be able to run these scripts in the integrated terminal of the remote server, but make it copy text to my local clipboard.

I suspect there might be a way to do this, since running code <dirname> in the remote terminal, for example, opens a vscode window in my local machine, so I assume there's a way to intercept the commands to make them do something locally even if they run on the remote machine. Any suggestions?

Mei Zhang
  • 1,434
  • 13
  • 29

1 Answers1

0

xsel might help you.

I'm trying to get a similar result using a dev container, although I could use some help myself. My problem is that I can't configure X11 forwarding. If you can set that up, then the following might move you forward a bit:

copy-to-clipboard-file() {
    [[ "$REGION_ACTIVE" -ne 0 ]] && zle copy-region-as-kill
    print -rn -- $CUTBUFFER > xsel --clipboard
}
zle -N copy-to-clipboard-file
bindkey "^X" copy-to-clipboard-file

I don't know if zle is available in your shell; I'm using zsh. This binds Ctrl-X to copy the selected text. You'll need to install xsel.

You'll know if X11 forwarding is working because this will output something:

echo $DISPLAY

Also see:

How do I highlight text for copying and pasting in the VS Code terminal?

FSCKur
  • 920
  • 7
  • 16