{ config, lib, pkgs, this, ... }: let cfg = config.nixfiles.modules.common.shell; in { options.nixfiles.modules.common.shell.aliases = lib.mkOption { description = "An attribute set of shell aliases."; type = with lib.types; attrsOf str; default = { }; }; config = { hm = { programs = { bash = { enable = true; initExtra = let aliasCompletions = lib.concatStringsSep "\n" ( lib.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 "${lib.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 = lib.listToAttrs ( map ( { name, value }: lib.nameValuePair name ( let pkg = if this.isHeadful then (pkgs.coreutils.overrideAttrs ( _: super: { patches = (super.patches or [ ]) ++ [ (pkgs.fetchpatch { url = "https://raw.githubusercontent.com/jarun/advcpmv/1e2b1c6b74fa0974896bf94604279a3f74b37a63/advcpmv-0.9-9.5.patch"; hash = "sha256-LRfb4heZlAUKiXl/hC/HgoqeGMxCt8ruBYZUrbzSH+Y="; }) ]; } )) else pkgs.coreutils; in "${lib.getExe' pkg "coreutils"} --coreutils-prog=${value}" ) ) ( let mkAlias = { name ? lib.head command, command, }: { inherit name; value = lib.concatStringsSep " " command; }; progressBar = lib.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:]'" ]; }) ] ) ) // (lib.genAttrs [ "grep" "egrep" "fgrep" ] (name: "${pkgs.gnugrep}/bin/${name} --color=always")) // cfg.aliases; }; dircolors.enable = true; command-not-found.enable = false; }; 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 ]; }; }; }