NixOS system configurations + dotfiles via home-manager
at main 55 lines 1.7 kB view raw
1{ 2 # https://github.com/helix-editor/helix/issues/966#issuecomment-3877313441 3 flake.modules.hjem.core = 4 { pkgs, ... }: 5 let 6 handleInput = # bash 7 '' 8 expression="''${1:-div}" 9 stdin="$(cat)" 10 11 tag=$(printf '%s' "$expression" | sed -n 's/\([^.#]*\).*/\1/p') 12 expression="''${expression:''${#tag}}" 13 14 id="$(printf '%s' "''${expression}" | sed -n 's/.*#\([^.#]*\).*/\1/p')" 15 expression="$(printf '%s' "$expression" | sed "s/#$id//")" 16 17 class="$(printf '%s' "$expression" | tr '.' ' ')" 18 class="''${class#"''${class%%[![:space:]]*}"}" 19 class="''${class%"''${class##*[![:space:]]}"}" 20 21 tagopen="$tag" 22 if [ -n "$id" ]; then tagopen="$tagopen id=\"$id\""; fi 23 if [ -n "$class" ]; then tagopen="$tagopen class=\"$class\""; fi 24 ''; 25 wrap-newline = pkgs.writeShellScriptBin "tag-wrap-newline" '' 26 ${handleInput} 27 content="$(printf '%s' "$stdin" | sed 's/^/ /')" 28 whitespace=$(printf '%s' "$stdin" | grep -o '^[[:space:]]*' | head -n1) 29 30 printf '%s\n' "$whitespace<$tagopen>" 31 printf '%s\n' "$content" 32 printf '%s\n' "$whitespace</$tag>" 33 ''; 34 wrap-inline = pkgs.writeShellScriptBin "tag-wrap-inline" '' 35 ${handleInput} 36 content="$(printf '%s' "$stdin")" 37 38 printf '%s' "<$tagopen>$content</$tag>" 39 ''; 40 in 41 { 42 packages = [ 43 wrap-newline 44 wrap-inline 45 ]; 46 47 helix.settings.keys = { 48 normal.m.t = "@|tag-wrap-inline "; 49 select.m.t = "@|tag-wrap-inline "; 50 51 normal.m.T = "@|tag-wrap-newline "; 52 select.m.T = "@|tag-wrap-newline "; 53 }; 54 }; 55}