Skip to content

Instantly share code, notes, and snippets.

@emptyflask
Created May 19, 2021 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emptyflask/abd3cfb6261256b1dcfec2dd29386708 to your computer and use it in GitHub Desktop.
Save emptyflask/abd3cfb6261256b1dcfec2dd29386708 to your computer and use it in GitHub Desktop.
Generate load icons for Xmobar (with nix support)
{ nixpkgs ? import <nixpkgs> {} }:
with nixpkgs;
let
ImageBase = perlPackages.buildPerlPackage {
pname = "Image-Base";
version = "1.17";
src = fetchurl {
url = "mirror://cpan/authors/id/K/KR/KRYDE/Image-Base-1.17.tar.gz";
sha256 = "f6d0d4d03026ba6a19d2ac3495171fc123522345630cadc7f43b53a667b95f81";
};
meta = {
description = "Base class for image manipulation";
};
};
ImageXpm = perlPackages.buildPerlPackage {
pname = "Image-Xpm";
version = "1.13";
src = fetchurl {
url = "mirror://cpan/authors/id/S/SR/SREZIC/Image-Xpm-1.13.tar.gz";
sha256 = "55da78fccf4c19d3d173fab38fc6ce6df0078f839a8a3e699199e4ef19428803";
};
propagatedBuildInputs = [ ImageBase ];
meta = {
description = "Load, create, manipulate and save xpm image files";
license = stdenv.lib.licenses.gpl2Plus;
};
};
in stdenv.mkDerivation {
name = "xmobar-icons";
version = "0.0.1";
buildInputs = [
perl
ImageXpm
];
}
#!/usr/bin/env perl
use warnings;
use strict;
use Image::Xpm;
use POSIX;
my $iwidth = 8;
my $iheight = 24;
my $pixels_per = 2;
my $color_none = "none";
my $color_bg = "#1d2021";
my $color_fg_h = "#cc241d";
my $color_fg_m = "#d79921";
my $color_fg_l = "#98971a";
for ( my $file_num = 0; $file_num <= 8; $file_num++ ) {
my $fname = "load_$file_num.xpm";
unlink $fname;
my $i = Image::Xpm->new(-file => $fname, -width => $iwidth, -height => $iheight);
my $h = $file_num * $pixels_per;
for ( my $x = 0; $x < $iwidth; $x++ ) {
for ( my $y = 0; $y < $iheight; $y++ ) {
if ($y > $iheight - 6 || $y < 2) {
$i->xy($x, $y, $color_none);
}
else {
$i->xy($x, $y, $color_bg);
}
}
}
for ( my $x = 0; $x < $iwidth; $x++ ) {
for ( my $y = ($iheight - 6); $y >= ($iheight - 6 - $h); $y-- ) {
my $col = do {
if ($file_num <= 2) {
$color_fg_l;
} elsif ($file_num <= 5) {
$color_fg_m;
} else {
$color_fg_h;
}
};
$i->xy($x, $y, $col);
}
}
$i->save;
}
@emptyflask
Copy link
Author

These colors work well for a Gruvbox themed desktop.
Thanks to @jaor for the original script.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment