{ pkgs, ... }@all: with all;
{
  home.packages = with pkgs; [
    fish
    any-nix-shell

    (writeShellScriptBin "nxfetch" ''
      logo=$(echo -e "

      ⠀⠀⠀⠀⠰⣿⣧⠀⠀⠹⣿⣧⠀⣴⣿⠆⠀⠀⠀⠀  OS
      ⠀⠀⠀⣀⣀⣹⣿⣧⣀⣀⠘⣿⣿⣿⠏⠀⠀⠀⠀⠀  DE/WM
      ⠀⠀⠼⠿⠿⠿⠿⠿⠿⠿⠦⠘⣿⣿⡀⠀⣼⣧⠀⠀  TERM
      ⠀⠀⠀⠀⢠⣶⡶⠀⠀⠀⠀⠀⠈⠿⢁⣼⣿⠋⠀⠀  SHELL
      ⢾⣿⣿⣿⣿⡿⠁⠀⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⡷  ISHELL
      ⠀⠀⣠⣿⡟⢁⣶⡀⠀⠀⠀⠀⠀⠾⠿⠃⠀⠀⠀⠀  KERNEL
      ⠀⠀⢻⡟⠀⠈⢿⣿⡄⠲⣶⣶⣶⣶⣶⣶⣶⡖⠀⠀  EDITOR
      ⠀⠀⠀⠀⠀⣰⣿⣿⣿⡄⠉⠉⢻⣿⣏⠉⠉⠀⠀⠀  TFM
      ⠀⠀⠀⠀⠰⣿⠟⠀⢻⣿⣆⠀⠀⠻⣿⠆⠀⠀⠀⠀  PROMPT

        " | lolcat --force 2> /dev/null)

        msg="
        $(echo -e "$logo" | sed -n 3p): $(cat /etc/*-release | grep PRETTY_NAME | cut -c 14- | rev | cut -c 2- | rev)
        $(echo -e "$logo" | sed -n 4p): ''${XDG_CURRENT_DESKTOP^}
        $(echo -e "$logo" | sed -n 5p): ''${TERM^}
        $(echo -e "$logo" | sed -n 6p): $(bash --version | head --lines 1 | cut -f -4 -d' ' | sed -E 's-(.*?), version (.*?)\(.*-\1 \2-g')
        $(echo -e "$logo" | sed -n 7p): fish $(fish --version | rev | cut -f 1 -d' ' | rev | sed 's/./\U&/')
        $(echo -e "$logo" | sed -n 8p): ''$(uname -r)
        $(echo -e "$logo" | sed -n 9p): $($EDITOR --version | head -n 1 | sed -E 's-(.+?) \(.*-\1-g' | sed 's/./\U&/')
        $(echo -e "$logo" | sed -n 10p): $(yazi --version | sed -E 's-(.*?) \(.*-\1-g')
        $(echo -e "$logo" | sed -n 11p): $(starship --version | head -n 1 | sed 's/./\U&/')
        "
        echo -e "$msg"
    '')
  ];

  # bash>>fish  is set in users system module

  programs.fish = {
    enable = true;
    shellAliases = let
      base-eza = "eza --icons --git --smart-group --group-directories-first";
    in {
      ls = "${base-eza}"; 
      ll = "${base-eza} --long"; 
      lg = "${base-eza} --group --long"; 
      la = "${base-eza} --all"; 
      lla = "${base-eza} --all --long"; 
      lt = "${base-eza} --long --tree"; 
      ltd = "${base-eza} --long --tree -D"; 
      lt2 = "${base-eza} --long --tree -L 2"; 
      sr = "sudo reboot"; 
      nf = "neofetch"; 
      nxf = "nxfetch"; 
      nn = "nano"; 
      hxx = "hx .";
      p = "python"; 
      ipy = "ipython"; 
      c = "codium"; 
      cc = "codium ."; 
      code = "codium"; 
      g = "git"; 
      lzg = "lazygit";
      # gst = "git status";
      gps = "git push"; 
      gpl = "git pull";
      gad = "git add";
      gcm = "git commit -m ";
      gmr = "git merge";
      gin = "git init";
      gdf = "git diff";
      grs = "git reset";
      grh = "git reset --hard";
      gch = "git checkout";
      gsh = "git stash";
      gsp = "git stash pop";
      glg = "git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)' --all";
      gll = "git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'";
      gmt = "git_monitor";
      gsw = "git switch";
      gft = "git fetch";
      ns = "nix-shell";
      nd = "nix develop -c fish";
      lzd = "lazydocker";
      d = "docker";
      dcmp = "docker compose";
      stui = "sudo systemctl-tui";
      # nxsent = ''sent -c \${rice.color.foreground} -b \${rice.color.background}'';

      # ya = "yazi"; # function
      # nxfiglet = "figlet"; 
    };
    interactiveShellInit = /* fish */ ''
      set -g fish_greeting
      if not set -q IN_NIX_SHELL
        if set -q SESSION_FROM_DE
          set tmp (mktemp -t "yazi-cwd.XXXXX")
          yazi --cwd-file="$tmp"
          if set cwd (cat -- "$tmp"); and [ -n "$cwd" ]; and [ "$cwd" != "$PWD" ]
              builtin cd -- "$cwd"
          end
          rm -f -- "$tmp"
        end
        nxfetch
        set -e SESSION_FROM_DE
      end
    '';
    functions = {
      take = /* bash */ ''
        mkdir $argv
        cd $argv
      '';
      nx_backup = let
        destination = if hyper.host == "NxNORTH" then "${hyper.home}/shared/" else "${hyper.home}/backups/";
      in pkgs.lib.mkIf (hyper.host != "NxACE") ''
        set RPATH (curl -s https://${hyper.domain}/latest-backup)
        rsync -avz --info=progress2 -e "ssh -p ${builtins.toString secrets.ssh.port}" ${hyper.user}@ssh.${hyper.domain}:"$RPATH" ${destination}
      '';
      # gpg = '';
      #   set bold \e[1m
      #   set green \e[32m
      #   set blue \e[34m
      #   set yellow \e[33m
      #   set cyan \e[36m
      #   set purple \e[35m
      #   set reset \e[0m

      #   if string match -r -- "--list-(secret|public)?-?keys?" "$argv"
      #     set output (command gpg $argv)

      #     if test -z "$output"
      #       return $status
      #     end

      #     echo "$output" | sed -e 's/(Key fingerprint =)/'$yellow'\1'$reset'/g' \
      #                          -e 's/(.*\.kbx)/'$yellow'Keyring: \1'$reset'/g' \
      #                          -e 's/^uid[[:blank:]]+/uid   /g' \
      #                          -e 's/(^uid.*\] )(.*)/\1'$green'\2'$reset'/g' \
      #                          -e 's/(\[.*\])/'$cyan'\1'$reset'/g' \
      #                          -e 's/(^pub|^sec)/'$bold$green'\1'$reset'/g' \
      #                          -e 's/(^sub|^ssb|^uid)/'$bold'\1'$reset'/g' \
      #                          -e 's/(\[expires: )([0-9]{4}-[0-9]{2}-[0-9]{2})(\].*)/'$cyan'\1'$blue'\2'$cyan'\3'$reset'/g' \
      #                          -e 's/([0-9]{4}-[0-9]{2}-[0-9]{2})/'$blue'\1'$reset'/g' \
      #                          -e 's/^$/------------------------------------------/g' \
      #                          -e 's| ([[:alnum:]]*)/| '$purple'\1'$reset'/|g' \
      #                          -e 's|'$HOME'|~|g'

      #     # Print info footer
      #     set info_footer "------------------------------------------\n"
      #     set info_footer $info_footer $cyan"E"$reset"=encryption, "
      #     set info_footer $info_footer $cyan"S"$reset"=signing, "
      #     set info_footer $info_footer $cyan"C"$reset"=certification, "
      #     set info_footer $info_footer $cyan"A"$reset"=authentication\n"
      #     set info_footer $info_footer $green$bold"pub"$reset"=public primary key, "
      #     set info_footer $info_footer $bold"sub"$reset"=public subkey,\n"
      #     set info_footer $info_footer $green$bold"sec"$reset"=secret primary key, "
      #     set info_footer $info_footer $bold"ssb"$reset"=secret subkey,\n"
      #     set info_footer $info_footer $bold"uid"$reset"=user ID, "$purple"algorithm"$reset"/"$bold"key-ID"$reset

      #     echo -e $info_footer
      #   else
      #     command gpg $argv
      #   end
      # '';
    };
  }; 
}
