|
1 | 1 | { system ? builtins.currentSystem |
2 | 2 | , pkgs ? import ../nixpkgs.nix { inherit system; } |
| 3 | +, config ? { } |
3 | 4 | }: |
4 | 5 | let |
5 | 6 | lib = builtins // pkgs.lib; |
@@ -111,27 +112,41 @@ rec { |
111 | 112 | opCmd = { name, help, interpolate, ... }: |
112 | 113 | let |
113 | 114 | len = maxCommandLength - (lib.stringLength name); |
| 115 | + |
| 116 | + nameWidth = toString maxCommandLength; |
| 117 | + helpWidth = toString (config.devshell.menu.width - (maxCommandLength + 5)); |
| 118 | + helpHeight = toString 100; |
| 119 | + |
| 120 | + processHelp = x: |
| 121 | + if (if interpolate != null then interpolate else menuConfig.interpolate) |
| 122 | + then ''\'' + "\n" + |
| 123 | + '' |
| 124 | + "$( |
| 125 | + cat << EOF |
| 126 | + ${x} |
| 127 | + EOF |
| 128 | + )" |
| 129 | + '' |
| 130 | + else lib.escapeShellArg x; |
| 131 | + |
| 132 | + highlyUnlikelyName = "ABDH_OKKD_VOAP_DOEE_PJGD"; |
| 133 | + |
| 134 | + command = '' |
| 135 | + ${highlyUnlikelyName}=${ |
| 136 | + if help == null || help == "" |
| 137 | + then "" |
| 138 | + else processHelp help |
| 139 | + } |
| 140 | + ${lib.getExe pkgs.perl} ${./scripts/formatCommand.pl} '${toString nameWidth}' '${helpWidth}' '${helpHeight}' '${name}' "''$${highlyUnlikelyName}"''; |
114 | 141 | in |
115 | | - if help == null || help == "" then |
116 | | - "printf ' ${name}'" |
117 | | - else |
118 | | - "printf ' ${pad name len} - '\n" + |
119 | | - ( |
120 | | - let |
121 | | - highlyUnlikelyName = "ABDH_OKKD_VOAP_DOEE_PJGD"; |
122 | | - quotedName = ( |
123 | | - x: |
124 | | - if (if interpolate != null then interpolate else menuConfig.interpolate) |
125 | | - then ''${x}'' |
126 | | - else "'${x}'" |
127 | | - ) |
128 | | - highlyUnlikelyName; |
129 | | - in |
130 | | - "cat <<${quotedName}\n${help}\n${highlyUnlikelyName}\n" |
131 | | - ); |
| 142 | + command; |
| 143 | + commandsColumns = lib.concatMapStringsSep "\n" opCmd cmd; |
132 | 144 | in |
133 | | - ''printf '\n${ansi.bold}[${category}]${ansi.reset}\n\n'' |
134 | | - + "'\n\n" + lib.concatStringsSep "\n" (map opCmd cmd); |
| 145 | + '' |
| 146 | + printf '\n${ansi.bold}[${category}]${ansi.reset}\n\n' |
| 147 | + |
| 148 | + ${commandsColumns} |
| 149 | + ''; |
135 | 150 | in |
136 | 151 | lib.concatStringsSep "\n" (map opCat commandByCategoriesSorted) + "\n"; |
137 | 152 | } |
0 commit comments