{ config, inputs, pkgs, ... }:

{
    home.packages = [
        pkgs.fzy
        pkgs.lf
        pkgs.curl
        pkgs.fd
        pkgs.zsh-powerlevel10k
        pkgs.zsh-autocomplete
        pkgs.zsh-vi-mode
        pkgs.ripgrep
        pkgs.rsync
        pkgs.moreutils
        inputs.fzgo.packages.${pkgs.system}.default
    ];
    home.sessionVariables = {
        BROWSER = "firefox";
        PDF_VIEWER = "evince";
        GPULAB_CERT = "${config.xdg.configHome}/../.secrets/GPULab/certificate.pem";
        GPULAB_DEV = "False";
        GCC_COLORS = "error = '01;31:warning = '01;35:note = '01;36:caret = '01;32:locus = '01:quote = '01'";
        ARCHFLAGS = "-arch x86_64";
        TERM = "screen-256color";
        PYTHONDONTWRITEBYTECODE = "1";
        GOPATH = "${config.xdg.dataHome}/go";
        DIRENV_LOG_FORMAT = "";
        OPENER = "${pkgs.handlr-regex}/bin/handlr open";
    };
    programs.direnv = {
        enable = true;
        nix-direnv.enable = true;
        config = {
            global = {
                hiden_env_diff = true;
                warn_timeout = 0;
            };
        };
    };
    home.file."${config.xdg.configHome}/direnv/direnvrc".text = ''
      : "''${XDG_CACHE_HOME:="''${HOME}/.cache"}"
      declare -A direnv_layout_dirs
      direnv_layout_dir() {
          local hash path
              echo "''${direnv_layout_dirs[$PWD]:=$(
                      hash="$(sha1sum - <<< "$PWD" | head -c40)"
                      path="''${PWD//[^a-zA-Z0-9]/-}"
                      echo "''${XDG_CACHE_HOME}/direnv/layouts/''${hash}''${path}"
                      )}"
      }
    '';
    programs.fzf = { enable = true; };
    programs.zsh = {
        enable = true;
        enableCompletion = true;
        syntaxHighlighting.enable = false;
        autosuggestion.enable = true;
        initContent = pkgs.lib.mkBefore ''
            ZVM_VI_INSERT_ESCAPE_BINDKEY=jj
            export LD_LIBRARY_PATH=${pkgs.sqlite.out}/lib:$LD_LIBRARY_PATH
            source ${./files/waypipe.zsh}
            source ${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/powerlevel10k.zsh-theme
            source ${./files/p10k.zsh}
            source ${pkgs.zsh-vi-mode}/share/zsh-vi-mode/zsh-vi-mode.plugin.zsh
            source ${./files/functions.zsh}
            source ${./files/fzgo.zsh}
            function zvm_after_init() {
                source ${./files/term.zsh}
                source ${./files/completion.zsh}
                if [ -n "\$\{commands[fzf-share]\}" ]; then
                    source "$(fzf-share)/key-bindings.zsh"
                    source "$(fzf-share)/completion.zsh"
                fi
                source ${./files/keys.zsh}
                eval "$(direnv hook zsh)"
                export LD_LIBRARY_PATH=${pkgs.sqlite.out}/lib:$LD_LIBRARY_PATH
            }
            function o() {
                  ${pkgs.handlr-regex}/bin/handlr open $@ < /dev/null &> /dev/null & disown
            }
        '';

        shellAliases = {
            mallorea = "run_waypipe mallorea";
            vault = "run_waypipe vault";
            riva = "run_waypipe riva";
            kell = "run_waypipe kell";
            aloria = "run_waypipe aloria";
            arch = "run_waypipe arch";

            ll = "ls -lhat";
            ls = "ls --color=auto";
            lf = ''cd "$(${pkgs.lf}/bin/lf -print-last-dir)"'';

            compress = "tar --use-compress-program = lbzip2 -cvf";
            wget = ''wget --hsts-file = "$XDG_DATA_HOME/wget-hsts"'';
            python = "python3";
            vim = "nvim";
            v = ''echo $(pwd) > /tmp/oil_dir && nvim -c ':lua require("oil").open()' && cd "$(cat /tmp/oil_dir 2> /dev/null || pwd)"'';
            cpr = "rsync --archive -hh --partial --info = stats1,progress2 --modify-window = 1";
            mvr = "rsync --archive -hh --partial --info = stats1,progress2 --modify-window = 1 --remove-source-files";
            rg = "rg -i --colors 'match:bg:yellow' --colors 'match:fg:black' --colors 'match:style:nobold' --colors 'path:fg:green' --colors 'path:style:bold' --colors 'line:fg:yellow' --colors 'line:style:bold'";
            ag = "rg -i --colors 'match:bg:yellow' --colors 'match:fg:black' --colors 'match:style:nobold' --colors 'path:fg:green' --colors 'path:style:bold' --colors 'line:fg:yellow' --colors 'line:style:bold'";
            reset = "tput reset";
        };
        history.size = 10000000;
        history.save = 10000000;
        history.path = "${config.xdg.dataHome}/zsh/history";
        autocd = true;
    };
}
