Skip to content

fish_clipboard_copy/paste: Handle redirected stdout/stdin#9271

Merged
faho merged 3 commits into
fish-shell:masterfrom
faho:clipboard-stdin
Oct 19, 2022
Merged

fish_clipboard_copy/paste: Handle redirected stdout/stdin#9271
faho merged 3 commits into
fish-shell:masterfrom
faho:clipboard-stdin

Conversation

@faho
Copy link
Copy Markdown
Member

@faho faho commented Oct 11, 2022

Description

This makes these tools usable in a pipe.

You can run

some-long-command | fish_clipboard_copy

to copy some command's output to your clipboard, and

fish_clipboard_paste | some-other-command

To feed your clipboard to some command.

For instance, let's say I want to insert my patented "commits missing from release X" table.

I've written a function called "gitcomp" to generate the info, and I have another function "mdtable" that transforms it to markdown. But I need it in my clipboard so I can paste it in the browser, and previously I'd use xsel --clipboard for that, which is very platform-dependent - if I switched to wayland I'd suddenly have to get used to a different thing!

So now I can instead do:

LANG=en_US.UTF-8 gitcomp | tail -n 5 | mdtable -d\t release commits percent date | fish_clipboard_copy

and paste directly into my browser to get:

release commits percent date
3.4.0 1106 5.7% 2022-03-12 22:31:57 +0800 (7 months ago)
3.4.1 9 5.7% 2022-03-26 00:27:56 +0800 (7 months ago)
3.5.0 433 3% 2022-06-16 21:02:33 +1000 (4 months ago)
3.5.1 24 2.9% 2022-07-20 18:15:47 +0800 (3 months ago)
HEAD 469 0%

and if I want to work on something from my clipboard, I can do

fish_clipboard_paste | something

and be reasonably sure it'll work.

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • [N/A] Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

@faho faho added this to the fish 3.6.0 milestone Oct 11, 2022
@mqudsi
Copy link
Copy Markdown
Contributor

mqudsi commented Oct 12, 2022

+1 for me; I forgot this wasn't already supported. It's one of the many clipboard-related things I can't live without as part of my fish config.

I also have support for copying the contents of a file or pasting the clipboard to a file when invoked as fish_clipboard_copy source.txt or fish_clipboard_paste dest.txt. This is, of course, just a shortcut for fish_clipboard_copy < source.txt and fish_clipboard_paste > dest.txt but I found it worth adding support for given how often I do it to copy contents between machines (together w/ the copy/paste-over-ssh support) or to a web browser (often for github issues).

Comment thread share/functions/fish_clipboard_paste.fish Outdated
Comment thread share/functions/fish_clipboard_copy.fish
Comment thread share/functions/fish_clipboard_paste.fish Outdated
Comment thread share/functions/fish_clipboard_paste.fish
faho added 3 commits October 19, 2022 20:06
This makes these tools usable in a pipe.

You can run

```fish
some-long-command | fish_clipboard_copy
```

to copy some command's output to your clipboard, and

```fish
fish_clipboard_paste | some-other-command
```

To feed your clipboard to some command.
(this did not recognize `[FILE DESC]` because of the space)
@faho faho merged commit 2419809 into fish-shell:master Oct 19, 2022
@faho faho deleted the clipboard-stdin branch October 26, 2022 10:19
@ilyagr
Copy link
Copy Markdown
Contributor

ilyagr commented Apr 13, 2023

Thank you so much! I just discovered this gem.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants