bash: allow unsetting shell options

This commit is contained in:
Renee Margaret McConahy 2021-08-23 01:28:21 -04:00 committed by Robert Helgesson
parent 039f786e60
commit 208e310e94
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
1 changed files with 12 additions and 3 deletions

View File

@ -75,7 +75,14 @@ in
# Warn if closing shell with running jobs.
"checkjobs"
];
description = "Shell options to set.";
example = [
"extglob"
"-cdspell"
];
description = ''
Shell options to set. Prefix an option with
<quote><literal>-</literal></quote> to unset.
'';
};
sessionVariables = mkOption {
@ -146,8 +153,10 @@ in
mapAttrsToList (k: v: "alias ${k}=${escapeShellArg v}") cfg.shellAliases
);
shoptsStr = concatStringsSep "\n" (
map (v: "shopt -s ${v}") cfg.shellOptions
shoptsStr = let
switch = v: if hasPrefix "-" v then "-u" else "-s";
in concatStringsSep "\n" (
map (v: "shopt ${switch v} ${removePrefix "-" v}") cfg.shellOptions
);
sessionVarsStr = config.lib.shell.exportAll cfg.sessionVariables;