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

47 lines
1.4 KiB
Nix
Raw Normal View History

2020-06-09 21:31:58 +02:00
# klem < klemm < klemmbrett ~ clipboard
{ pkgs, lib, ... }@args:
let
cfg = eval.config;
eval = lib.evalModules {
2020-06-10 17:37:25 +02:00
modules = [{
2020-06-09 21:31:58 +02:00
_file = toString ./klem.nix;
2020-06-10 17:37:25 +02:00
imports = [ (args.config or { }) ];
2020-06-09 21:31:58 +02:00
options = {
selection = lib.mkOption {
2020-06-09 21:31:58 +02:00
default = "clipboard";
2020-06-10 17:37:25 +02:00
type = lib.types.enum [ "primary" "secondary" "clipboard" ];
2020-06-09 21:31:58 +02:00
};
dmenu = lib.mkOption {
default = "${pkgs.dmenu}/bin/dmenu -i -p klem";
type = lib.types.path;
2020-06-16 19:13:10 +02:00
};
2020-06-09 21:31:58 +02:00
scripts = lib.mkOption {
default = {
pastebin = "${pkgs.curl}/bin/curl -fSs -F 'f:1=<-' ix.io";
2020-06-10 17:37:25 +02:00
shorten = ''
${pkgs.curl}/bin/curl -fSs -F "shorten=$(${pkgs.coreutils}/bin/cat)" https://0x0.st
'';
2020-06-09 21:31:58 +02:00
"replace p.r" = "${pkgs.gnused}/bin/sed 's/\\<r\\>/krebsco.de/'";
};
2020-06-10 16:36:52 +02:00
type = lib.types.attrs;
2020-06-09 21:31:58 +02:00
};
};
2020-06-10 17:37:25 +02:00
}];
2020-06-09 21:31:58 +02:00
};
scriptCase = option: script: ''
2020-06-10 16:36:52 +02:00
'${option}') ${toString script} ;;
2020-06-09 21:31:58 +02:00
'';
2020-06-10 17:37:25 +02:00
in pkgs.writers.writeDashBin "klem" ''
${pkgs.xclip}/bin/xclip -selection ${cfg.selection} -out \
2020-06-10 17:37:25 +02:00
| case $(echo "${
lib.concatStringsSep "\n" (lib.attrNames cfg.scripts)
}" | ${cfg.dmenu}) in
2020-06-09 21:31:58 +02:00
${lib.concatStringsSep "\n" (lib.mapAttrsToList scriptCase cfg.scripts)}
*) ${pkgs.coreutils}/bin/cat ;;
esac \
| tr -d '\r\n' \
| ${pkgs.xclip}/bin/xclip -selection ${cfg.selection} -in
2020-06-09 21:31:58 +02:00
''