{ config, inputs, lib, pkgs, this, ... }: with lib; let cfg = config.nixfiles.modules.common.shell; in { options.nixfiles.modules.common.shell.aliases = mkOption { description = "An attribute set of shell aliases."; type = with types; attrsOf str; default = { }; }; config = { hm = { imports = [ inputs.nix-index-database.hmModules.nix-index ]; programs = { bash = { enable = true; initExtra = let aliasCompletions = concatStringsSep "\n" ( mapAttrsToList (name: _: "complete -F _complete_alias ${name}") cfg.aliases ); in '' # Apropriated from the default NixOS prompt settings. if [ "$TERM" != "dumb" ] || [ -n "$INSIDE_EMACS" ]; then PROMPT_COLOR="1;31m" ((UID)) && PROMPT_COLOR="1;32m" if [ -n "$INSIDE_EMACS" ] || [ "$TERM" = "eterm" ] || [ "$TERM" = "eterm-color" ]; then PS1="\n\[\033[$PROMPT_COLOR\][\u@\h:\w]\\$\[\033[0m\] " else PS1="\n\[\033[$PROMPT_COLOR\][\[\e]0;\u@\h: \w\a\]\u@\h:\w]\\$\[\033[0m\] " fi if test "$TERM" = "xterm"; then PS1="\[\033]2;\h:\u:\w\007\]$PS1" fi fi source "${./functions.bash}" source "${getExe' pkgs.complete-alias "complete_alias"}" ${aliasCompletions} # https://github.com/garabik/grc?tab=readme-ov-file#bash GRC_ALIASES=true source ${pkgs.grc}/etc/profile.d/grc.sh ''; shellOptions = [ "autocd" "cdspell" "checkjobs" "checkwinsize" "dirspell" "extglob" "globstar" "histappend" "histreedit" "histverify" ]; historyControl = [ "erasedups" "ignoredups" "ignorespace" ]; shellAliases = listToAttrs ( map ( { name, value }: nameValuePair name ( with pkgs; let pkg = if this.isHeadful then (pkgs.coreutils.overrideAttrs ( _: super: { patches = (super.patches or [ ]) ++ [ (fetchpatch { url = "https://raw.githubusercontent.com/jarun/advcpmv/1e2b1c6b74fa0974896bf94604279a3f74b37a63/advcpmv-0.9-9.5.patch"; hash = "sha256-LRfb4heZlAUKiXl/hC/HgoqeGMxCt8ruBYZUrbzSH+Y="; }) ]; } )) else coreutils; in "${getExe' pkg "coreutils"} --coreutils-prog=${value}" ) ) ( let mkAlias = { name ? head command, command, }: { inherit name; value = concatStringsSep " " command; }; progressBar = optionalString this.isHeadful "--progress-bar"; in [ (mkAlias { command = [ "cp" "--interactive" "--recursive" progressBar ]; }) (mkAlias { command = [ "mv" "--interactive" progressBar ]; }) (mkAlias { command = [ "rm" "--interactive=once" ]; }) (mkAlias { command = [ "ln" "--interactive" ]; }) (mkAlias { command = [ "mkdir" "--parents" ]; }) (mkAlias { command = [ "rmdir" "--parents" ]; }) (mkAlias { name = "lower"; command = [ "tr" "'[:upper:]'" "'[:lower:]'" ]; }) (mkAlias { name = "upper"; command = [ "tr" "'[:lower:]'" "'[:upper:]'" ]; }) ] ) ) // (genAttrs [ "grep" "egrep" "fgrep" ] (name: "${pkgs.gnugrep}/bin/${name} --color=always")) // cfg.aliases; }; dircolors.enable = true; command-not-found.enable = false; nix-index-database.comma.enable = true; }; home.packages = with pkgs; [ grc ]; }; programs.command-not-found.enable = false; environment = { etc."grc.conf".source = "${pkgs.grc}/etc/grc.conf"; systemPackages = with pkgs; [ bc gawk hr moreutils pv ]; }; }; }