{ config, lib, pkgs, ... }:

let
  helpers = pkgs.writeText "bash.helpers"
    (builtins.readFile ../static/bash/bash.helpers);

  colors =
    pkgs.writeText "bash.colors" (builtins.readFile ../static/bash/bash.colors);

  env = pkgs.writeText "bash.env" (builtins.readFile ../static/bash/bash.env);

in {
  config.programs.bash = {
    shellAliases = {
      ll = "ls $LS_OPTIONS -alF";
      l = "ls $LS_OPTIONS -CF";
      la = "ls $LS_OPTIONS -A";
      ".." = "cd ..";
      "..." = "cd ../..";
      rm = "rm --one-file-system --preserve-root";
    };

    shellInit = ''
      if [ -d $HOME/bin ]; then
        PATH="$HOME/bin:$PATH"
      fi
    '';

    interactiveShellInit = ''
      case $TERM in
        screen|xterm*|rxvt*)
          export LS_OPTIONS="--color=auto"
          ;;
        *)
          export LS_OPTIONS=""
          ;;
      esac

      . ${colors}
      . ${helpers}
      . ${env}
    '';
  };
}