diff options
| author | Arpit Chakladar <arpitchakladar+git@gmail.com> | 2026-08-16 19:59:48 +0530 |
|---|---|---|
| committer | Arpit Chakladar <arpitchakladar+git@gmail.com> | 2026-08-29 03:50:26 +0530 |
| commit | 2d482bcb7f1f36d8ea017f5fa8091a896faead49 (patch) | |
| tree | ae694a0ebabd91d9781eaf1cd71a479853477f19 /modules/scripts/lib.nix | |
| parent | 7a3b718c3196e0b0129bee4a2705c7f2fb5b206f (diff) | |
| download | home-manager-config-2d482bcb7f1f36d8ea017f5fa8091a896faead49.tar.gz home-manager-config-2d482bcb7f1f36d8ea017f5fa8091a896faead49.zip | |
feat: added auto-completion for usque-warp, fixed usque-warp disconnect
- Added zsh auto-completion for usque-warp
- Fixed usque-warp disconnect
Diffstat (limited to 'modules/scripts/lib.nix')
| -rw-r--r-- | modules/scripts/lib.nix | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/modules/scripts/lib.nix b/modules/scripts/lib.nix index 70affba..77c0a20 100644 --- a/modules/scripts/lib.nix +++ b/modules/scripts/lib.nix @@ -1,9 +1,7 @@ { lib, pkgs }: let - shell = pkgs.runtimeShell; - mkScript = - name: path: description: env: deps: + name: path: description: env: deps: completion: let descLines = lib.filter (s: s != "") (lib.splitString "\n" description); descComment = @@ -11,17 +9,35 @@ let envVars = lib.concatStringsSep "\n" ( lib.mapAttrsToList (n: v: "export ${n}=${lib.escapeShellArg (toString v)}") env ); + base = pkgs.writeShellApplication { + inherit name; + runtimeInputs = deps; + text = '' + #!/usr/bin/env bash + ${descComment}${envVars} + ${builtins.readFile path} + ''; + }; + completionDrv = + pkgs.runCommand "${name}-completion" + { + nativeBuildInputs = [ pkgs.installShellFiles ]; + } + '' + installShellCompletion --zsh --name _${name} ${pkgs.writeText "_${name}" completion} + ''; in - pkgs.writeShellApplication { - inherit name; - runtimeInputs = deps; - text = '' - #!${shell} - ${descComment}${envVars} - ${builtins.readFile path} - ''; - }; - + if completion == null then + base + else + pkgs.symlinkJoin { + name = name; + paths = [ + base + completionDrv + ]; + meta = base.meta or { }; + }; mkScriptModule = { name, @@ -32,9 +48,10 @@ let extraLinks ? [ ], config, description ? "", + completion ? null, }: let - scriptDrv = mkScript name path description env deps; + scriptDrv = mkScript name path description env deps completion; in { options.scripts.${name} = { @@ -48,6 +65,13 @@ let readOnly = true; description = "The derivation for the ${name} script."; }; + completion = { + enable = lib.mkOption { + type = lib.types.bool; + default = completion != null; + description = "Whether to install a zsh completion for the ${name} script."; + }; + }; desktop = { enable = lib.mkOption { type = lib.types.bool; @@ -66,7 +90,6 @@ let }; }; }; - moduleConfig = { scripts.${name} = lib.mkIf config.scripts.${name}.enable ( { @@ -74,7 +97,6 @@ let } // lib.optionalAttrs (desktop != null) { inherit desktop; } ); - home.file = lib.mkIf config.scripts.${name}.enable ( builtins.listToAttrs ( map (linkPath: { @@ -85,7 +107,6 @@ let }) extraLinks ) ); - assertions = [ { assertion = @@ -94,6 +115,10 @@ let || config.terminal.kitty.enable; message = "scripts.${name}.desktop.enable requires terminal.kitty.enable because desktop entries launch scripts in kitty."; } + { + assertion = !config.scripts.${name}.completion.enable || completion != null; + message = "scripts.${name}.completion.enable is true but no completion text was provided to mkScriptModule."; + } ]; }; }; |
