diff --git a/modules/commands.nix b/modules/commands.nix index aac375e7..377f9fd1 100644 --- a/modules/commands.nix +++ b/modules/commands.nix @@ -1,6 +1,6 @@ { lib, config, pkgs, options, ... }: let - inherit (import ../nix/commands/lib.nix { inherit pkgs options; }) + inherit (import ../nix/commands/lib.nix { inherit pkgs options config; }) commandsType commandToPackage devshellMenuCommandName diff --git a/nix/commands/devshell.nix b/nix/commands/devshell.nix index c67ed16e..98e154d2 100644 --- a/nix/commands/devshell.nix +++ b/nix/commands/devshell.nix @@ -1,5 +1,6 @@ { system ? builtins.currentSystem , pkgs ? import ../nixpkgs.nix { inherit system; } +, config ? { } }: let lib = builtins // pkgs.lib; @@ -111,27 +112,41 @@ rec { opCmd = { name, help, interpolate, ... }: let len = maxCommandLength - (lib.stringLength name); + + nameWidth = toString maxCommandLength; + helpWidth = toString (config.devshell.menu.width - (maxCommandLength + 5)); + helpHeight = toString 100; + + processHelp = x: + if (if interpolate != null then interpolate else menuConfig.interpolate) + then ''\'' + "\n" + + '' + "$( + cat << EOF + ${x} + EOF + )" + '' + else lib.escapeShellArg x; + + highlyUnlikelyName = "ABDH_OKKD_VOAP_DOEE_PJGD"; + + command = '' + ${highlyUnlikelyName}=${ + if help == null || help == "" + then "" + else processHelp help + } + ${lib.getExe pkgs.perl} ${./scripts/formatCommand.pl} '${toString nameWidth}' '${helpWidth}' '${helpHeight}' '${name}' "''$${highlyUnlikelyName}"''; in - if help == null || help == "" then - "printf ' ${name}'" - else - "printf ' ${pad name len} - '\n" + - ( - let - highlyUnlikelyName = "ABDH_OKKD_VOAP_DOEE_PJGD"; - quotedName = ( - x: - if (if interpolate != null then interpolate else menuConfig.interpolate) - then ''${x}'' - else "'${x}'" - ) - highlyUnlikelyName; - in - "cat <<${quotedName}\n${help}\n${highlyUnlikelyName}\n" - ); + command; + commandsColumns = lib.concatMapStringsSep "\n" opCmd cmd; in - ''printf '\n${ansi.bold}[${category}]${ansi.reset}\n\n'' - + "'\n\n" + lib.concatStringsSep "\n" (map opCmd cmd); + '' + printf '\n${ansi.bold}[${category}]${ansi.reset}\n\n' + + ${commandsColumns} + ''; in lib.concatStringsSep "\n" (map opCat commandByCategoriesSorted) + "\n"; } diff --git a/nix/commands/lib.nix b/nix/commands/lib.nix index 7ee2dba0..8a22e2ac 100644 --- a/nix/commands/lib.nix +++ b/nix/commands/lib.nix @@ -1,7 +1,8 @@ { system ? builtins.currentSystem , pkgs ? import ../nixpkgs.nix { inherit system; } , options ? { } +, config ? { } }: (import ./types.nix { inherit pkgs options; }) // -(import ./devshell.nix { inherit pkgs; }) // +(import ./devshell.nix { inherit pkgs config; }) // (import ./commandsType.nix { inherit pkgs options; })