diff options
Diffstat (limited to 'modules/common/common/shell/default.nix')
-rw-r--r-- | modules/common/common/shell/default.nix | 266 |
1 files changed, 132 insertions, 134 deletions
diff --git a/modules/common/common/shell/default.nix b/modules/common/common/shell/default.nix index b05b279..b50459d 100644 --- a/modules/common/common/shell/default.nix +++ b/modules/common/common/shell/default.nix @@ -1,150 +1,148 @@ { + config, lib, pkgs, - pkgsStable, this, ... }: -with lib; { - hm = { - programs = { - bash = { - enable = true; - - shellOptions = [ - "autocd" - "cdspell" - "checkjobs" - "checkwinsize" - "dirspell" - "extglob" - "globstar" - "histappend" - "histreedit" - "histverify" - ]; - - profileExtra = '' - export _PROFILE_SOURCED=1 - ''; - - initExtra = '' - set -o notify - - # 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 - - ${readFile ./functions.bash} - - # https://github.com/garabik/grc?tab=readme-ov-file#bash - GRC_ALIASES=true - source ${pkgs.grc}/etc/profile.d/grc.sh +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 = {}; + }; - # https://github.com/akermu/emacs-libvterm?tab=readme-ov-file#shell-side-configuration - vterm_printf() { - if [ -n "$TMUX" ] && ([ "''${TERM%%-*}" = "tmux" ] || [ "''${TERM%%-*}" = "screen" ]); then - printf "\ePtmux;\e\e]%s\007\e\\" "$1" - elif [ "''${TERM%%-*}" = "screen" ]; then - printf "\eP\e]%s\007\e\\" "$1" - else - printf "\e]%s\e\\" "$1" + config = { + hm = { + 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 - } - - # This makes sure we always source these tweaks for both interactive - # and login sessions. - if [ -z "$_PROFILE_SOURCED" ] && [ -f "$HOME/.profile" ]; then - source "$HOME/.profile" - fi - ''; - - shellAliases = - listToAttrs - (map - ({ - name, - value, - }: - nameValuePair name (with pkgs; let - pkg = - if this.isHeadful - then - # FIXME Update this to 9.3 when patches[1] become available - # - # [1]: https://github.com/jarun/advcpmv - (pkgsStable.coreutils.overrideAttrs (_: _: { - patches = [ - (fetchpatch { - url = "https://raw.githubusercontent.com/jarun/advcpmv/ea268d870b475edd5960dcd55d5378abc9705958/advcpmv-0.9-9.1.patch"; - hash = "sha256-d+SRT/R4xmfHLAdOr7m4R3WFiW64P5ZH6iqDvErYCyg="; - }) - ]; - })) - else coreutils; - in "${pkg}/bin/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"); - historyControl = ["erasedups" "ignoredups" "ignorespace"]; + 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/a1f8b505e691737db2f7f2b96275802c45f65c59/advcpmv-0.9-9.3.patch"; + hash = "sha256-I25F7uHESUsMDZFYTv8/56eR8QwelIPpABRXTgvszQI="; + }) + ]; + })) + 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; + }; + + command-not-found.enable = false; + + dircolors.enable = true; }; - command-not-found.enable = false; - - dircolors.enable = true; + home.packages = with pkgs; [grc]; }; - home.packages = with pkgs; [grc]; - }; - - environment = { - etc."grc.conf".source = "${pkgs.grc}/etc/grc.conf"; + environment = { + etc."grc.conf".source = "${pkgs.grc}/etc/grc.conf"; - systemPackages = with pkgs; [ - bash-completion - bc - gawk - hr - moreutils - pv - ]; + systemPackages = with pkgs; [ + bc + gawk + hr + moreutils + pv + ]; + }; }; } |