4

I often find myself wanting to make a quick graph to illustrate dependencies or a process. dot is nice for doing this, however it would be much more convenient if I could generate the rendered graph straight to my clipboard instead of generating a temporary file.

Ideally, I'd like something like

echo "graph {a--b; b--c;}" | dot -Tpng | xclip

This command as-written doesn't quite work - the copied data won't paste into applications that normally accept pasted images.

Is there any trick to get dot to produce output that would be pastable into applications?

As a tangent, and perhaps to address the knowledge gap at the root of my problem, what makes images "pastable" to begin with? What is the difference between my command above and, say, right-clicking on an image in a web browser and choosing Copy Image?

TJ Ellis
  • 143
  • 4

1 Answers1

5

Close. You need to tell xclip the type of data, and most programs want the XA_CLIPBOARD for the usual ctrl-v pasting:

echo "graph {a--b; b--c;}" | dot -Tpng | xclip -selection clipboard -t image/png

A simple shell function might be a good idea to wrap all this.

By the way, if you're pasting into inkscape (probably also in quite a few things like web editors), SVG might be a better choice than PNG, dot -Tsvg | xclip -selection clipboard -t image/svg.

Marcus Müller
  • 769
  • 6
  • 20
  • Perfect, `-t image/png` is exactly what I was looking for! I forgot to include the `-selection clipboard` in my question example because i use an alias with that option included – TJ Ellis May 24 '21 at 15:58