Skip to content

Commit f94016c

Browse files
committed
feat: interpolate individual help
1 parent e17d69b commit f94016c

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

modules/commands.nix

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ in
4242
{
4343
help = "prints this menu";
4444
name = devshellMenuCommandName;
45-
command = ''
46-
cat <<${(x: if config.devshell.menu.interpolate then x else "'${x}'") "DEVSHELL_MENU"}
47-
${commandsToMenu config.commands}
48-
DEVSHELL_MENU
49-
'';
45+
command = commandsToMenu config.devshell.menu config.commands;
5046
}
5147
];
5248

nix/commands/devshell.nix

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ rec {
4545
then null
4646
else cmd.package;
4747

48-
commandsToMenu = cmds:
48+
commandsToMenu = menuConfig: cmds:
4949
let
5050
cleanName = { name, package, ... }@cmd:
5151
if
@@ -108,16 +108,30 @@ rec {
108108
let
109109
category = kv.name;
110110
cmd = kv.value;
111-
opCmd = { name, help, ... }:
111+
opCmd = { name, help, interpolate, ... }:
112112
let
113113
len = maxCommandLength - (lib.stringLength name);
114114
in
115115
if help == null || help == "" then
116-
" ${name}"
116+
"printf ' ${name}'"
117117
else
118-
" ${pad name len} - ${help}";
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+
);
119132
in
120-
"\n${ansi.bold}[${category}]${ansi.reset}\n\n" + lib.concatStringsSep "\n" (map opCmd cmd);
133+
''printf '\n${ansi.bold}[${category}]${ansi.reset}\n\n''
134+
+ "'\n\n" + lib.concatStringsSep "\n" (map opCmd cmd);
121135
in
122136
lib.concatStringsSep "\n" (map opCat commandByCategoriesSorted) + "\n";
123137
}

0 commit comments

Comments
 (0)