diff --git a/configs/i3.nix b/configs/i3.nix index 807dbb5..dd3f1af 100644 --- a/configs/i3.nix +++ b/configs/i3.nix @@ -1,5 +1,9 @@ { config, pkgs, lib, ... }: let + klem = pkgs.callPackage { + inherit pkgs; + }; + scripts = import { inherit pkgs lib; }; myLib = import { 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}"; diff --git a/packages/scripts/klem.nix b/packages/scripts/klem.nix new file mode 100644 index 0000000..5d5d693 --- /dev/null +++ b/packages/scripts/klem.nix @@ -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/\\/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 +'' diff --git a/packages/scripts/klemmbrett.sh b/packages/scripts/klemmbrett.sh deleted file mode 100755 index a81f1d8..0000000 --- a/packages/scripts/klemmbrett.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -options='Pastebin -Shorten -[Replace p.r]' - -r_to_krebscode() { - sed 's/\/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