summaryrefslogtreecommitdiff
path: root/users/kassouni/palette/fuzzel-palette.nix
blob: d6d4774f74e586f685cdc59f0832afc4dd5f76f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.kassouni.palette;
in
{
  # Wayland front end for the palette. `--index` is fuzzel's answer to rofi's
  # `-format i`, so the same index-into-exes trick works. Unlike rofi, fuzzel
  # will happily accept text that matches no row; it exits non-zero there, but
  # the numeric guard keeps a surprising build of fuzzel from indexing the
  # array with garbage.
  home.packages = [
    (pkgs.writers.writeBashBin "open-palette-fuzzel" ''
      set -eu
      exes=(${lib.concatMapStringsSep " " (c: "${c.exe}") cfg.commands})
      idx=$(${pkgs.fuzzel}/bin/fuzzel --dmenu --index --prompt "palette " <<EOF
${lib.concatMapStrings (c: "${c.icon} ${c.name}\n") cfg.commands}EOF
      )
      [[ $idx =~ ^[0-9]+$ ]] && [[ $idx -lt ''${#exes[@]} ]] || exit 1
      exec "''${exes[$idx]}"
    '')
  ];
}