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

60 lines
1.5 KiB
Nix
Raw Normal View History

2020-06-09 21:31:58 +02:00
# klem < klemm < klemmbrett ~ clipboard
2022-03-10 21:52:12 +01:00
{
lib,
dmenu,
curl,
gnused,
coreutils,
xclip,
libnotify,
writers,
options ? { },
2022-03-10 21:52:12 +01:00
...
}: let
2020-06-09 21:31:58 +02:00
eval = lib.evalModules {
2022-03-10 21:52:12 +01:00
modules = [
{
imports = [options];
2022-03-10 21:52:12 +01:00
options = {
selection = lib.mkOption {
default = "clipboard";
type = lib.types.enum ["primary" "secondary" "clipboard"];
};
dmenu = lib.mkOption {
default = "${dmenu}/bin/dmenu -i -p klem";
2022-03-10 21:52:12 +01:00
type = lib.types.path;
};
scripts = lib.mkOption {
default = {
pastebin = "${curl}/bin/curl -fSs -F 'f:1=<-' ix.io";
2022-03-10 21:52:12 +01:00
shorten = ''
${curl}/bin/curl -fSs -F "shorten=$(${coreutils}/bin/cat)" https://0x0.st
2022-03-10 21:52:12 +01:00
'';
"replace p.r" = "${gnused}/bin/sed 's/\\<r\\>/krebsco.de/'";
2022-03-10 21:52:12 +01:00
};
type = lib.types.attrs;
2020-06-09 21:31:58 +02:00
};
};
2022-03-10 21:52:12 +01:00
}
];
2020-06-09 21:31:58 +02:00
};
cfg = eval.config;
2022-03-10 21:52:12 +01:00
in
writers.writeDashBin "klem" ''
2023-03-20 12:23:36 +01:00
set -efu
${xclip}/bin/xclip -selection ${cfg.selection} -out \
2022-03-10 21:52:12 +01:00
| case $(echo "${
2020-06-10 17:37:25 +02:00
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 ;;
2022-03-10 21:52:12 +01:00
esac \
| ${xclip}/bin/xclip -selection ${cfg.selection} -in
2023-03-20 12:23:36 +01:00
${libnotify}/bin/notify-send --app-name="klem" "Result copied to clipboard."
2022-03-10 21:52:12 +01:00
''