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