08.30X Clipboard Magic Hackery
Dramatic title, no? In any case, you may or may not know that you can do some really awesome stuff using the X clipboard in Linux.
For example, one of the things I often find myself doing something like this:
cat something.log | xclip -selection clipboard
This basically copies the file contents of something.log to the X clipboard.
For stackoverflow junkies, you can use a nice little sed command to tab the output so you’ll be able to directly paste code into a question and have it formatted in Markdown properly:
cat ProblemChild.java | sed 's:^:\t:g' | xclip -selection clipboard
The above will insert a tab before each line as it copies ProblemChild.java to the clipboard.
Let’s finish off with some awesome hackery. What if you’ve copied something to the clipboard but need to format it for StackOverflow? Well, it’s really not too hard:
xclip -o | sed 's:^:\t:g' | xclip -selection clipboard
This dumps the clipboard to standard out, inserts a tab on each line at the beginning, then fills the clipboard with the new content. Talk about winning!

[...] posted an awesome new little tutorial on TerminalLinux.org on getting your awesome on with the X clipboard on your Linux machine. [...]
August 30th, 2011 at 6:24 pm
[...] posted an awesome new little tutorial on TerminalLinux.org on getting your awesome on with the X clipboard on your Linux machine. [...]
August 30th, 2011 at 6:34 pm