From e6ed60548397627bf10f561f9438201dbba0a36e Mon Sep 17 00:00:00 2001 From: Azat Bahawi Date: Sun, 21 Apr 2024 02:15:42 +0300 Subject: 2024-04-21 --- modules/common/shell/default.nix | 208 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 modules/common/shell/default.nix (limited to 'modules/common/shell/default.nix') diff --git a/modules/common/shell/default.nix b/modules/common/shell/default.nix new file mode 100644 index 0000000..437ce57 --- /dev/null +++ b/modules/common/shell/default.nix @@ -0,0 +1,208 @@ +{ + 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/a1f8b505e691737db2f7f2b96275802c45f65c59/advcpmv-0.9-9.4.patch"; + hash = "sha256-4fdqpkENPfra4nFQU4+xNrlfq6Dw/2JIZXUOMmdMtcM="; + }) + ]; + } + )) + 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 + ]; + }; + }; +} -- cgit 1.4.1