fix(cli): keep values in env load hints from running as shell code

The hint is a comment in the output people feed to eval, so a line break in a selector value ended the comment and ran the rest. Such a value now prints as a placeholder. Fish and PowerShell always get quotes, because the plain-word rule is POSIX and @team is a splat in PowerShell. Addresses the review of #74.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura committed 2026-11-04 01:45:09 -06:00
1 parent 8c46a546b7
commit b8b58ca59e
3 files changed
+58 -1

No files matched your search

@@ -39,6 +39,21 @@ public final class ShellExport {
};
}
/** Whether {@code shell} is one of the POSIX family, as opposed to fish or PowerShell. */
public static boolean isPosix(String shell) {
return switch (shell.toLowerCase()) {
case "fish", "powershell", "pwsh", "ps1" -> false;
default -> true;
};
}
/** Whether {@code value} could end the comment line it is printed in, in any shell. */
public static boolean breaksLine(String value) {
return value.chars().anyMatch(c -> Character.isISOControl(c)
|| Character.getType(c) == Character.LINE_SEPARATOR
|| Character.getType(c) == Character.PARAGRAPH_SEPARATOR);
}
/** {@code value} as one single-quoted argument in the given shell. */
public static String quoted(String shell, String value) {
return switch (shell.toLowerCase()) {