blog // ~snubspreker

this is just a test

select color from terminal

May 25, 2020 — ~snubspreker

colorpicker

Use colorpicker from the command line to select colors.

For instance: surf ((echo "https://www.colorhexa.com/")(colorpicker –short –one-shot –preview | tr -d "#"))

As usual, there is most probably a better way to do this, but anyway. We break it down into several steps.

$(colorpicker –short –one-shot –preview | tr -d "#")

What this does is first call colorpicker with *–short which returns html color codes, –one-shot whcih cause colorpicker to exit after one click, and –preview* which displays a small square in the bottom right corner of the screen filled with the color under the cursor.

Pipe this into tr using *-d to delete the hash #*.

Wrap the whole thing in a command substitution.

surf $(echo "https://www.colorhexa.com/" … )

This is simple you echo the url concat with the previous command sub result and generate a url to pass to surf or your favorite browser.

Alternative

colorpicker –short –one-shot –preview | xclip -sel clip

Just pipe the result of colorpicker into xclip or any other clipboard manager, and you can paste the result into your code.

I have a keybinding in stumpwm (define-key top-map (kbd "s-c") "exec colorpicker –short –one-shot –preview | xclip -sel clip") So that I can grab colors on the fly.