Live data from Hacker News

Yank: Yank Terminal Output to Clipboard

github.com

51–57 of 57 posts

Re: Yank: Yank Terminal Output to Clipboard

#51

Useful tool indeed, thanks for sharing. I use clipper[1], which delivers a similar function through a different implementation. What I like about that one is that with right config you can also pipe output from remote servers back into your machine's clipboard, which is quite handy in so many situations. [1] https://github.com/wincent/clipper

There's a better way to do it. Terminals have a special escape sequence called OSC 52, which allows you to insert into the clipboard from even remote SSH sessions. Try this: printf "\033]52;c;$(printf "%s" "blabla" | base64)\a"

Hey, that's quite interesting. Just tested it here with alacritty and was able to get data from a remote server into the clipboard. The downside here is that it did not seem to work immediately from inside tmux, but a quick search shows that there are ways to make it work. Also found a vim-plugin[1] that would allow it to work from inside vim as well. If I can also find a way to pipe random commands to it, it might indeed work better than clipper for my use cases. Finally, there is the added benefit of removing the need to forward the local UNIX socket over SSH, which I find to be a bit flaky. Thanks for sharing it!

[1] https://github.com/ojroques/vim-oscyank

Re: Yank: Yank Terminal Output to Clipboard

#52

Useful tool indeed, thanks for sharing. I use clipper[1], which delivers a similar function through a different implementation. What I like about that one is that with right config you can also pipe output from remote servers back into your machine's clipboard, which is quite handy in so many situations. [1] https://github.com/wincent/clipper

There's a better way to do it. Terminals have a special escape sequence called OSC 52, which allows you to insert into the clipboard from even remote SSH sessions. Try this: printf "\033]52;c;$(printf "%s" "blabla" | base64)\a"

I've found a couple of random blog posts and some user's pages laying out the OSC codes, but is there an open reference of them?

I have also considered trawling through the various terminal emulator source repos in order to know which are actually implemented (since that can for sure be a different set from those which are specified)

Re: Yank: Yank Terminal Output to Clipboard

#53
post #5

You can do this with tmux too. ~/.tmux.conf: # export to clipboard. bind-key > run-shell -b 'tmux save-buffer - | xclip' # paste from clipboard. bind-key (edit: my actual setup is slightly different. It interacts with a Windows clipboard via ssh where the terminal is running. cf. https://github.com/euske/pyrexecd/blob/master/tools/tmux.con... )

I use xsel : ./command | xsel -ib

Re: Yank: Yank Terminal Output to Clipboard

#55

On Mac OS, a much less powerful but built in tool is `pbcopy`.

To replicate pbcoby on X11 systems, add to your bashrc: alias clip="xclip -selection clipboard" `echo hello | clip` will copy 'hello' to the clipboard, and similarly `ls | clip` will copy a bunch of lines to the clipboard. You might need to install xclip through your package manger (the package is just named xclip on Arch).

This is how I make pbcopy/pbpaste work on both Linux and WSL (Windows Subsystem for Linux).

    if [[ "$(uname)" == "Linux" ]]; then
      if ! grep -q Microsoft /proc/version; then
        alias pbcopy='xsel --clipboard --input'
        alias pbpaste='xsel --clipboard --output'
      else
        alias pbcopy='clip.exe'
        alias pbpaste='powershell.exe -command "Get-Clipboard"'
      fi
    fi

Re: Yank: Yank Terminal Output to Clipboard

#56
post #20

The final example `yank -- xsel -b` is probably the most directly useful for me, but it still doesn't solve the following problem which irritates me to all hell: $ git push fatal: The current branch new has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin new Is there any sane way to copy the perfectly formatted `git push -u` command shown above without…

I think “thefuck” handles this case really well: https://github.com/nvbn/thefuck

This is perfect, because it's an after-the-fact solution instead of me trying to remember to type the right git command in the first place, much like copy-pasting the suggested command is. Thanks for the suggestion!

Re: Yank: Yank Terminal Output to Clipboard

#57
post #35

I've been using ubuntu for over a decade and I have no idea how the clipboard works. There seems to be multiple clipboards and I have no idea when I am using which. I generally spam some combination of ctrl-v, shift-insert, rightclick context menu paste, middleclick, etc until I get what I want. I've abandoned vim for a gui solely because I have no idea how to copy stuff to/from it. Can someone finally explain it to…

Same, which is why I made my own bash aliases which basically streams files and text into temporary files in my home directory. I can then paste them as plaintext or move them as files. Should make a function to keep a list of the 10 latest files and query those then.
Post reply on HN