From 8a209007e263c03368744b3a42d0be98d708fb10 Mon Sep 17 00:00:00 2001 From: ilaumjd Date: Tue, 3 Oct 2023 07:34:46 +0700 Subject: [PATCH] zsh-abbr: add module --- modules/lib/maintainers.nix | 6 ++++ modules/misc/news.nix | 8 +++++ modules/modules.nix | 1 + modules/programs/zsh/zsh-abbr.nix | 40 +++++++++++++++++++++++++ tests/modules/programs/zsh/default.nix | 1 + tests/modules/programs/zsh/zsh-abbr.nix | 17 +++++++++++ 6 files changed, 73 insertions(+) create mode 100644 modules/programs/zsh/zsh-abbr.nix create mode 100644 tests/modules/programs/zsh/zsh-abbr.nix diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 7fd3c180b..64c721e46 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 af2899354..f52969df7 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 76c742cca..cb42ea7e3 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 000000000..8b6189c52 --- /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 fcfb642ff..25aa3b470 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 000000000..0e016fafe --- /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'" + ''; +}