diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index de25f70c..7e835212 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -257,6 +257,12 @@ githubId = 605641; name = "Bart Bakker"; }; + ilaumjd = { + name = "Ilham AM"; + email = "ilaumjd@gmail.com"; + github = "ilaumjd"; + githubId = 16514431; + }; jrobsonchase = { email = "josh@robsonchase.com"; github = "jrobsonchase"; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index af289935..f52969df 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1258,6 +1258,14 @@ in A new module is available: 'programs.khard'. ''; } + + { + time = "2023-10-04T06:06:08+00:00"; + condition = config.programs.zsh.enable; + message = '' + A new module is available: 'programs.zsh.zsh-abbr' + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 76c742cc..cb42ea7e 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -237,6 +237,7 @@ let ./programs/zplug.nix ./programs/zsh.nix ./programs/zsh/prezto.nix + ./programs/zsh/zsh-abbr.nix ./services/autorandr.nix ./services/avizo.nix ./services/barrier.nix diff --git a/modules/programs/zsh/zsh-abbr.nix b/modules/programs/zsh/zsh-abbr.nix new file mode 100644 index 00000000..8b6189c5 --- /dev/null +++ b/modules/programs/zsh/zsh-abbr.nix @@ -0,0 +1,40 @@ +{ config, lib, pkgs, ... }: + +with lib; +let cfg = config.programs.zsh.zsh-abbr; +in { + meta.maintainers = [ hm.maintainers.ilaumjd ]; + + options.programs.zsh.zsh-abbr = { + enable = + mkEnableOption "zsh-abbr - zsh manager for auto-expanding abbreviations"; + + abbreviations = mkOption { + type = types.attrsOf types.str; + default = { }; + example = { + l = "less"; + gco = "git checkout"; + }; + description = '' + An attribute set that maps aliases (the top level attribute names + in this option) to abbreviations. Abbreviations are expanded with + the longer phrase after they are entered. + ''; + }; + }; + + config = mkIf cfg.enable { + programs.zsh.plugins = [{ + name = "zsh-abbr"; + src = pkgs.zsh-abbr; + file = "/share/zsh/zsh-abbr/abbr.plugin.zsh"; + }]; + + xdg.configFile = { + "zsh-abbr/user-abbreviations".text = concatStringsSep "\n" + (mapAttrsToList (k: v: "abbr ${escapeShellArg k}=${escapeShellArg v}") + cfg.abbreviations) + "\n"; + }; + }; +} diff --git a/tests/modules/programs/zsh/default.nix b/tests/modules/programs/zsh/default.nix index fcfb642f..25aa3b47 100644 --- a/tests/modules/programs/zsh/default.nix +++ b/tests/modules/programs/zsh/default.nix @@ -8,4 +8,5 @@ zsh-history-substring-search = ./history-substring-search.nix; zsh-prezto = ./prezto.nix; zsh-syntax-highlighting = ./syntax-highlighting.nix; + zsh-abbr = ./zsh-abbr.nix; } diff --git a/tests/modules/programs/zsh/zsh-abbr.nix b/tests/modules/programs/zsh/zsh-abbr.nix new file mode 100644 index 00000000..0e016faf --- /dev/null +++ b/tests/modules/programs/zsh/zsh-abbr.nix @@ -0,0 +1,17 @@ +{ ... }: + +{ + programs.zsh.zsh-abbr = { + enable = true; + abbreviations = { ga = "git add"; }; + }; + + test.stubs.zsh-abbr = { }; + + nmt.script = '' + abbreviations=home-files/.config/zsh-abbr/user-abbreviations + + assertFileExists $abbreviations + assertFileContains $abbreviations "abbr 'ga'='git add'" + ''; +}