{pkgs, ...}: let
  hakase-hyprlock-typewriter = pkgs.writeShellScriptBin "hakase-hyprlock-typewriter" ''
    text="$1"
    if [[ -z "$text" ]]; then
      echo "Usage: $(basename "$0") [text]"
      exit 1
    fi
    state_file="''${XDG_RUNTIME_DIR:-/tmp}/typewriter_pos"
    blink_file="''${XDG_RUNTIME_DIR:-/tmp}/typewriter_blink"
    pid_file="''${XDG_RUNTIME_DIR:-/tmp}/typewriter_pid"

    current_pid=$(pgrep -x hyprlock | head -1)

    if [[ -f $pid_file ]]; then
      old_pid=$(cat $pid_file)
      if [[ "''${old_pid}" != "''${current_pid}"  ]]; then
        rm -f "$state_file" "$blink_file"
      fi
    fi
    echo "$current_pid" >"$pid_file"

    if [[ ! -f $state_file ]]; then
      echo 0 >"$state_file"
    fi

    if [[ ! -f $blink_file ]]; then
      echo 0 >"$blink_file"
    fi

    len=''${#text}
    letter=$(cat "$state_file")
    blink=$(cat "$blink_file")

    if [[ $letter -lt $len ]]; then
      letter=$((letter + 1))
      echo "$letter" >"$state_file"
      echo "''${text:0:$letter}_"
    else
      # Toggle every 4 calls (at 200ms update = ~800ms blink)
      if (((blink / 20) % 2 == 0)); then
        echo "''${text}_"
      else
        echo "''${text}<span alpha=\"1%\">_</span>"
      fi
    fi

    blink=$((blink + 1))
    echo "$blink" >"$blink_file"
  '';
  hakase-test-hyprlock-typewriter = pkgs.writeShellScriptBin "hakase-test-hyprlock-typewriter" ''
    for i in {1..10}; do
      hakase-hyprlock-typewriter
    done
  '';
in {
  home.packages = [
    hakase-hyprlock-typewriter
    hakase-test-hyprlock-typewriter
  ];
}
