1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00
Files
niveum/packages/klem.nix
2026-01-06 22:46:12 +01:00

57 lines
1.3 KiB
Nix

# klem < klemm < klemmbrett ~ clipboard
{
lib,
dmenu,
curl,
gnused,
coreutils,
wl-clipboard,
libnotify,
writers,
options ? { },
...
}:
let
eval = lib.evalModules {
modules = [
{
imports = [ options ];
options = {
dmenu = lib.mkOption {
default = "${dmenu}/bin/dmenu -i -p klem";
type = lib.types.path;
};
scripts = lib.mkOption {
default = {
pastebin = "${curl}/bin/curl -fSs -F 'f:1=<-' ix.io";
shorten = ''
${curl}/bin/curl -fSs -F "shorten=$(${coreutils}/bin/cat)" https://0x0.st
'';
"replace p.r" = "${gnused}/bin/sed 's/\\<r\\>/krebsco.de/'";
};
type = lib.types.attrs;
};
};
}
];
};
cfg = eval.config;
in
writers.writeDashBin "klem" ''
set -efu
${wl-clipboard}/bin/wl-paste \
| case $(echo "${lib.concatStringsSep "\n" (lib.attrNames cfg.scripts)}" | ${cfg.dmenu}) in
${lib.concatStringsSep "\n" (
lib.mapAttrsToList (option: script: ''
'${option}') ${toString script} ;;
'') cfg.scripts
)}
*) ${coreutils}/bin/cat ;;
esac \
| ${wl-clipboard}/bin/wl-copy
${libnotify}/bin/notify-send --app-name="klem" "Result copied to clipboard."
''