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 = {
|
|
|
|
|
clipboardSelection = lib.mkOption {
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
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" ''
|
2020-06-09 21:31:58 +02:00
|
|
|
${pkgs.xclip}/bin/xclip -selection ${cfg.clipboardSelection} -out \
|
2020-06-10 17:37:25 +02:00
|
|
|
| case $(echo "${
|
|
|
|
|
lib.concatStringsSep "\n" (lib.attrNames cfg.scripts)
|
|
|
|
|
}" | ${pkgs.dmenu}/bin/dmenu -i -p klem) 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.clipboardSelection} -in
|
|
|
|
|
''
|