A very simple example of the flexibility and philosophy of Linux

Rezoner
4 min readDec 2, 2017

--

I am a gamedeveloper — what I do often is getting sprite coords from a texture atlas into the game code. When I am tired and I cannot memorize 4 numbers I tend to alt+tab every number to switch between code and image editor.

Alt tabbing a lot.

What if I could have a handy shortcut that brings up a small popup with a text box that goes directly to the clipboard so I can write the coords down without cycling between apps?

First I will show you what I mean then I will explain how I managed to do that from scratch in a couple of minutes.

The philosophy of Linux

I can launch my IDE of choice, pick a favorite GUI library and spend another hour googling for how to get into the clipboard of my system.

Or I can recall this summary of Unix philosophy:

  • Write programs that do one thing and do it well.
  • Write programs to work together.
  • Write programs to handle text streams, because that is a universal interface.

It means what it says. It’s highly possible that there are already programs that joined together can do what you want. It’s the matter of finding them.

A program that puts some text in the clipboard.

Run your command line (terminal) and type:

> echo "this is going to the clipboard" | xsel --clipboard

That’s all you need to put some text into the clipboard. It’s not a bash tutorial but it literally says put the output of echo “…” command into xsel program. If you get back to the Unix principles I’ve listed you will understand why seemingly ugly bash looks that way and why it’s great for what it’s meant to do — gluing individual programs together. Someone wrote a program that fills the clipboard with any text so I don’t have to. Thank you good soul.

A program that builds a GUI on the fly.

When I first read about Zenity I was astonished by how clever and simple this idea is. It gives you ability to turn your text based bash scripts into convenient windows applications with just one line of text.

The very basic usage that we need is to display an entry box which is synonymous with an text input element.

> zenity --entry

Hit enter and you will see this:

It will return whatever you type in that box. I hope you see where this is going — let’s put zenity output into xsel input and we are done.

Glue it together.

zenity --entry | xsel --clipboard

Just brilliant. All we need to do is to make it an executable script. So I’ve saved that in my ~/bin/ folder and named it handy-clipboard (yes, there is no extension). Now make it executable:

> chmod +x ~/bin/handy-clipboard

And voilà — we have just wrote another program that is contributing to and taking from the Unix philosophy. Every time you type handy-clipboard in the console you will get your popup.

We do not want to run it from console.

Of course we don’t. Let’s make a keyboard shortcut that will bring the thing up. My Linux flavor is Ubuntu and that’s how you assign keyboard shortcuts on Ubuntu:

Launch the keyboard settings and add the shortcut.

That’s all folks

Let me know in the comments if you want me to show you some other things that Linux does to ease my day — next time with less motivational phrases and more meat.

I highly encourage you to give Linux a try. This is one of the secrets for how I manage to get so much done as a single person studio. I have automated countless things using this approach — from managing my servers to rendering 3D models, turning them into spritesheets, adjusting the palette and putting it in the game with just one click. Of course console programs are not meant to replace complex applications but they are here to take a great portion of your mundane tasks away.

TL;DR

Run this to get a text input which puts its contents into the clipboard.

Extra

Diego wrote me a little GIMP plugin that does the same thing https://twitter.com/feiss/status/937139364617912322 :)

--

--