This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / modules / klem.nix
2.6 kB 95 lines
1{ 2 self, 3 config, 4 lib, 5 pkgs, 6 ... 7}: 8with lib; 9let 10 cfg = config.lass.klem; 11 slib = self.inputs.stockholm.lib; 12in 13{ 14 options.lass.klem = mkOption { 15 default = { }; 16 type = types.attrsOf ( 17 types.submodule ( 18 { config, ... }: 19 { 20 options = { 21 target = mkOption { 22 default = ".*"; 23 description = '' 24 regex of valid targets 25 can be shown with xclip -selection clipboard -t TARGETS 26 the first hit is taken as target argument 27 ''; 28 type = types.str; 29 }; 30 script = mkOption { 31 description = '' 32 file to run if entry is selected 33 ''; 34 type = types.path; 35 }; 36 label = mkOption { 37 default = config._module.args.name; 38 description = '' 39 label to show in dmenu for this script 40 ''; 41 type = types.str; 42 }; 43 }; 44 } 45 ) 46 ); 47 }; 48 config = 49 let 50 klem = pkgs.writers.writeDashBin "klem" '' 51 set -x 52 53 labels="" 54 # match filetype against patterns 55 ${concatMapStringsSep "\n" (script: '' 56 ${pkgs.xclip}/bin/xclip -selection clipboard -target TARGETS -out \ 57 | ${pkgs.gnugrep}/bin/grep -q '${script.target}' 58 if [ $? -eq 0 ]; then 59 labels="$labels:${script.label}" 60 fi 61 '') (attrValues cfg)} 62 63 #remove empty line, feed into dmenu 64 script=$(echo "$labels" \ 65 | ${pkgs.gnused}/bin/sed 's/^://;s/:/\n/g' \ 66 | ${pkgs.dmenu}/bin/dmenu) 67 68 #run the chosen script 69 case $script in 70 ${concatMapStringsSep "\n" ( 71 script: 72 slib.indent '' 73 ${script.label}) 74 target=$(${pkgs.xclip}/bin/xclip -selection clipboard -target TARGETS -out \ 75 | ${pkgs.gnugrep}/bin/grep '${script.target}' \ 76 | ${pkgs.gnugrep}/bin/grep -v TARGETS \ 77 | ${pkgs.coreutils}/bin/head -1) 78 ${pkgs.xclip}/bin/xclip -selection clipboard -target "$target" -out \ 79 | ${script.script} \ 80 | ${pkgs.xclip}/bin/xclip -selection clipboard -in 81 ;; 82 '' 83 ) (attrValues cfg)} 84 esac 85 ''; 86 in 87 mkIf (cfg != { }) { 88 environment.systemPackages = [ klem ]; 89 nixpkgs.overlays = [ 90 (_self: _super: { 91 klem = klem; 92 }) 93 ]; 94 }; 95}