summaryrefslogtreecommitdiff
path: root/modules/common/common/shell/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/common/common/shell/default.nix')
-rw-r--r--modules/common/common/shell/default.nix218
1 files changed, 136 insertions, 82 deletions
diff --git a/modules/common/common/shell/default.nix b/modules/common/common/shell/default.nix
index 8c3fa8a..883bfae 100644
--- a/modules/common/common/shell/default.nix
+++ b/modules/common/common/shell/default.nix
@@ -6,53 +6,55 @@
this,
...
}:
-with lib; let
+with lib;
+let
cfg = config.nixfiles.modules.common.shell;
-in {
+in
+{
options.nixfiles.modules.common.shell.aliases = mkOption {
description = "An attribute set of shell aliases.";
type = with types; attrsOf str;
- default = {};
+ default = { };
};
config = {
hm = {
- imports = [inputs.nix-index-database.hmModules.nix-index];
+ 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
+ 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 "${./functions.bash}"
- source "${getExe' pkgs.complete-alias "complete_alias"}"
- ${aliasCompletions}
+ 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
- '';
+ # https://github.com/garabik/grc?tab=readme-ov-file#bash
+ GRC_ALIASES=true
+ source ${pkgs.grc}/etc/profile.d/grc.sh
+ '';
shellOptions = [
"autocd"
@@ -74,57 +76,109 @@ in {
];
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;
- };
+ 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"))
+ 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;
};
@@ -134,7 +188,7 @@ in {
nix-index-database.comma.enable = true;
};
- home.packages = with pkgs; [grc];
+ home.packages = with pkgs; [ grc ];
};
environment = {