Question

Is there a way to write a script that would be applied to the clipboard content ( I'm using Linux\Gentoo)?

When copy-pasting it would be nice to bind a keystroke that would (e.g -) remove all line breaks from the copied text.

I couldn't find where to start such a task (where should such a script be placed\how to reference the clipboard) so just a hint of where to start would be appreciated.

Thanks!

Was it helpful?

Solution

You need to install xsel to access your clipboard. Then you can just use a small script and piping. I use this to prepend four spaces to my current selection in order to get a version I can paste into StackOverflow editors:

xsel | while IFS='' read a; do echo "    $a"; done | xsel

Default for xsel is to manipulate (or query) your PRIMARY selection (what you just marked with the mouse). You can use the clipboard (C-c, C-v stuff) instead by using the option -b.

To remove all line breaks from your current clipboard, just try this:

xsel -b | tr '\n' '\r' | sed 's/\r*//g' | xsel -b
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top