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

feat: klem - clipboard filter

This commit is contained in:
Kierán Meinhardt
2020-06-09 21:31:58 +02:00
parent 8b835c1252
commit 70cc121237
3 changed files with 45 additions and 29 deletions

View File

@@ -1,5 +1,9 @@
{ config, pkgs, lib, ... }:
let
klem = pkgs.callPackage <niveum/packages/scripts/klem.nix> {
inherit pkgs;
};
scripts = import <niveum/packages/scripts> { inherit pkgs lib; };
myLib = import <niveum/lib> { inherit pkgs; };
inherit (myLib) writeTOML;
@@ -143,6 +147,8 @@ in with config.niveum; {
"${modifier}+k" = "focus up";
"${modifier}+l" = "focus right";
"${modifier}+Menu" = "exec ${klem}/bin/klem";
"${modifier}+Shift+b" = "move window to workspace prev";
"${modifier}+Shift+n" = "move window to workspace next";
"${modifier}+Shift+x" = "exec --no-startup-id ${move-to-new-workspace}";

39
packages/scripts/klem.nix Normal file
View File

@@ -0,0 +1,39 @@
# klem < klemm < klemmbrett ~ clipboard
{ pkgs, lib, ... }@args:
let
cfg = eval.config;
eval = lib.evalModules {
modules = [ {
_file = toString ./klem.nix;
imports = [ (args.config or {}) ];
options = {
clipboardSelection = lib.mkOption {
default = "clipboard";
type = lib.types.enum ["primary" "secondary" "clipboard"];
};
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.attrsOf lib.types.str;
};
};
} ];
};
scriptCase = option: script: ''
'${option}') ${script} ;;
'';
in
pkgs.writers.writeDashBin "klem" ''
${pkgs.xclip}/bin/xclip -selection ${cfg.clipboardSelection} -out \
| case $(echo "${lib.concatStringsSep "\n" (lib.attrNames cfg.scripts)}" | ${pkgs.dmenu}/bin/dmenu -i -p klem) in
${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
''

View File

@@ -1,29 +0,0 @@
#!/bin/sh
options='Pastebin
Shorten
[Replace p.r]'
r_to_krebscode() {
sed 's/\<r\>/krebsco.de/'
}
modify_clipboard() {
case $(echo "$options" | dmenu -i -p 'clipboard') in
'Pastebin')
curl -fSs -F 'f:1=<-' ix.io
# curl -fSs http://p.r --data-binary @- | tail --lines=1 | r_to_krebscode
;;
'Shorten')
# curl -fSs "http://tinyurl.com/api-create.php?url=$(cat)"
curl -fSs "https://0x0.st" -F "shorten=$(cat)"
# curl -fSs http://go.r -F "uri=$(cat)"
;;
'Replace p.r') r_to_krebscode ;;
*) cat;;
esac
}
xclip -selection clipboard -out \
| modify_clipboard \
| tr -d '\r\n' \
| xclip -selection clipboard -in