Restructure Nix options to nest shopts under line/core/prompt submodules matching shopt key paths

This commit is contained in:
2026-03-21 03:26:00 -04:00
parent 627489905e
commit 898002812e
2 changed files with 173 additions and 148 deletions

View File

@@ -49,38 +49,38 @@ ${indented}
autocmdLines = lib.concatLines (map mkAutoCmd cfg.autocmds);
in
lib.concatLines [
cfg.settings.extraPreConfig
cfg.extraPreConfig
(lib.concatLines (lib.mapAttrsToList (name: value: "export ${name}=\"${value}\"") cfg.environmentVars))
(lib.concatLines (lib.mapAttrsToList (name: value: "alias ${name}=\"${value}\"") cfg.aliases))
(lib.concatLines [
"shopt line.viewport_height=${toString cfg.settings.viewportHeight}"
"shopt line.scroll_offset=${toString cfg.settings.scrollOffset}"
"shopt line.viewport_height=${toString cfg.shopts.line.viewport_height}"
"shopt line.scroll_offset=${toString cfg.shopts.line.scroll_offset}"
"shopt core.dotglob=${boolToString cfg.settings.dotGlob}"
"shopt core.autocd=${boolToString cfg.settings.autocd}"
"shopt core.hist_ignore_dupes=${boolToString cfg.settings.historyIgnoresDupes}"
"shopt core.max_hist=${toString cfg.settings.maxHistoryEntries}"
"shopt core.interactive_comments=${boolToString cfg.settings.interactiveComments}"
"shopt core.auto_hist=${boolToString cfg.settings.autoHistory}"
"shopt core.bell_enabled=${boolToString cfg.settings.bellEnabled}"
"shopt core.max_recurse_depth=${toString cfg.settings.maxRecurseDepth}"
"shopt core.xpg_echo=${boolToString cfg.settings.echoExpandsEscapes}"
"shopt core.noclobber=${boolToString cfg.settings.noClobber}"
"shopt core.dotglob=${boolToString cfg.shopts.core.dotglob}"
"shopt core.autocd=${boolToString cfg.shopts.core.autocd}"
"shopt core.hist_ignore_dupes=${boolToString cfg.shopts.core.hist_ignore_dupes}"
"shopt core.max_hist=${toString cfg.shopts.core.max_hist}"
"shopt core.interactive_comments=${boolToString cfg.shopts.core.interactive_comments}"
"shopt core.auto_hist=${boolToString cfg.shopts.core.auto_hist}"
"shopt core.bell_enabled=${boolToString cfg.shopts.core.bell_enabled}"
"shopt core.max_recurse_depth=${toString cfg.shopts.core.max_recurse_depth}"
"shopt core.xpg_echo=${boolToString cfg.shopts.core.xpg_echo}"
"shopt core.noclobber=${boolToString cfg.shopts.core.noclobber}"
"shopt prompt.leader='${cfg.settings.leaderKey}'"
"shopt prompt.trunc_prompt_path=${toString cfg.settings.promptPathSegments}"
"shopt prompt.comp_limit=${toString cfg.settings.completionLimit}"
"shopt prompt.highlight=${boolToString cfg.settings.syntaxHighlighting}"
"shopt prompt.linebreak_on_incomplete=${boolToString cfg.settings.linebreakOnIncomplete}"
"shopt prompt.line_numbers=${boolToString cfg.settings.lineNumbers}"
"shopt prompt.screensaver_idle_time=${toString cfg.settings.screensaverIdleTime}"
"shopt prompt.screensaver_cmd='${cfg.settings.screensaverCmd}'"
"shopt prompt.completion_ignore_case=${boolToString cfg.settings.completionIgnoreCase}"
"shopt prompt.auto_indent=${boolToString cfg.settings.autoIndent}"
"shopt prompt.leader='${cfg.shopts.prompt.leader}'"
"shopt prompt.trunc_prompt_path=${toString cfg.shopts.prompt.trunc_prompt_path}"
"shopt prompt.comp_limit=${toString cfg.shopts.prompt.comp_limit}"
"shopt prompt.highlight=${boolToString cfg.shopts.prompt.highlight}"
"shopt prompt.linebreak_on_incomplete=${boolToString cfg.shopts.prompt.linebreak_on_incomplete}"
"shopt prompt.line_numbers=${boolToString cfg.shopts.prompt.line_numbers}"
"shopt prompt.screensaver_idle_time=${toString cfg.shopts.prompt.screensaver_idle_time}"
"shopt prompt.screensaver_cmd='${cfg.shopts.prompt.screensaver_cmd}'"
"shopt prompt.completion_ignore_case=${boolToString cfg.shopts.prompt.completion_ignore_case}"
"shopt prompt.auto_indent=${boolToString cfg.shopts.prompt.auto_indent}"
functionLines
completeLines
keymapLines
autocmdLines
])
cfg.settings.extraPostConfig
cfg.extraPostConfig
]

View File

@@ -155,137 +155,162 @@
description = "Additional completion scripts to source when shed starts (e.g. for custom tools or functions)";
};
viewportHeight = {
type = lib.types.either lib.types.int lib.types.str;
default = "50%";
description = "Maximum viewport height for the line editor buffer";
};
scrollOffset = {
type = lib.types.int;
default = "1";
description = "The minimum number of lines to keep visible above and below the cursor when scrolling (i.e. the 'scrolloff' option in vim)";
};
environmentVars = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
default = {};
description = "Environment variables to set when shed starts";
};
settings = {
dotGlob = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to include hidden files in glob patterns";
};
autocd = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to automatically change into directories when they are entered as commands";
};
historyIgnoresDupes = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to ignore duplicate entries in the command history";
};
maxHistoryEntries = lib.mkOption {
type = lib.types.int;
default = 10000;
description = "The maximum number of entries to keep in the command history";
};
interactiveComments = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to allow comments in interactive mode";
};
autoHistory = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to automatically add commands to the history as they are executed";
};
bellEnabled = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to allow shed to ring the terminal bell on certain events (e.g. command completion, errors, etc.)";
};
maxRecurseDepth = lib.mkOption {
type = lib.types.int;
default = 1000;
description = "The maximum depth to allow when recursively executing shell functions";
};
echoExpandsEscapes = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to have the 'echo' builtin expand escape sequences like \\n and \\t (if false, it will print them verbatim)";
};
noClobber = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to prevent redirection from overwriting existing files by default (i.e. behave as if 'set -o noclobber' is always in effect)";
shopts = lib.mkOption {
type = lib.types.submodule {
options = {
line = lib.mkOption {
type = lib.types.submodule {
options = {
viewport_height = lib.mkOption {
type = lib.types.either lib.types.int lib.types.str;
default = "50%";
description = "Maximum viewport height for the line editor buffer";
};
scroll_offset = lib.mkOption {
type = lib.types.int;
default = 1;
description = "The minimum number of lines to keep visible above and below the cursor when scrolling (i.e. the 'scrolloff' option in vim)";
};
};
};
default = {};
description = "Settings related to the line editor (i.e. the 'shopt line.*' options)";
};
core = lib.mkOption {
type = lib.types.submodule {
options = {
dotglob = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to include hidden files in glob patterns";
};
autocd = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to automatically change into directories when they are entered as commands";
};
hist_ignore_dupes = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to ignore duplicate entries in the command history";
};
max_hist = lib.mkOption {
type = lib.types.int;
default = 10000;
description = "The maximum number of entries to keep in the command history";
};
interactive_comments = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to allow comments in interactive mode";
};
auto_hist = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to automatically add commands to the history as they are executed";
};
bell_enabled = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to allow shed to ring the terminal bell on certain events (e.g. command completion, errors, etc.)";
};
max_recurse_depth = lib.mkOption {
type = lib.types.int;
default = 1000;
description = "The maximum depth to allow when recursively executing shell functions";
};
xpg_echo = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to have the 'echo' builtin expand escape sequences like \\n and \\t (if false, it will print them verbatim)";
};
noclobber = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to prevent redirection from overwriting existing files by default (i.e. behave as if 'set -o noclobber' is always in effect)";
};
};
};
default = {};
description = "Core settings (i.e. the 'shopt core.*' options)";
};
prompt = lib.mkOption {
type = lib.types.submodule {
options = {
leader = lib.mkOption {
type = lib.types.str;
default = "\\\\";
description = "The leader key to use for custom keymaps (e.g. if set to '\\\\', then a keymap with keys='x' would be triggered by '\\x')";
};
trunc_prompt_path = lib.mkOption {
type = lib.types.int;
default = 4;
description = "The maximum number of path segments to show in the prompt";
};
comp_limit = lib.mkOption {
type = lib.types.int;
default = 1000;
description = "The maximum number of completion candidates to show before truncating the list";
};
highlight = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to enable syntax highlighting in the shell";
};
linebreak_on_incomplete = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to automatically insert a newline when the input is incomplete";
};
line_numbers = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to show line numbers in the prompt";
};
screensaver_cmd = lib.mkOption {
type = lib.types.str;
default = "";
description = "A shell command to execute after a period of inactivity (i.e. a custom screensaver)";
};
screensaver_idle_time = lib.mkOption {
type = lib.types.int;
default = 0;
description = "The amount of inactivity time in seconds before the screensaver command is executed";
};
completion_ignore_case = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to ignore case when completing commands and file names";
};
auto_indent = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to automatically indent new lines based on the previous line";
};
};
};
default = {};
description = "Settings related to the prompt (i.e. the 'shopt prompt.*' options)";
};
};
};
default = {};
};
leaderKey = lib.mkOption {
type = lib.types.str;
default = "\\\\";
description = "The leader key to use for custom keymaps (e.g. if set to '\\\\', then a keymap with keys='x' would be triggered by '\\x')";
};
promptPathSegments = lib.mkOption {
type = lib.types.int;
default = 4;
description = "The maximum number of path segments to show in the prompt";
};
completionLimit = lib.mkOption {
type = lib.types.int;
default = 1000;
description = "The maximum number of completion candidates to show before truncating the list";
};
syntaxHighlighting = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to enable syntax highlighting in the shell";
};
linebreakOnIncomplete = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to automatically insert a newline when the input is incomplete";
};
lineNumbers = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to show line numbers in the prompt";
};
screensaverCmd = lib.mkOption {
type = lib.types.str;
default = "";
description = "A shell command to execute after a period of inactivity (i.e. a custom screensaver)";
};
screensaverIdleTime = lib.mkOption {
type = lib.types.int;
default = 0;
description = "The amount of inactivity time in seconds before the screensaver command is executed";
};
completionIgnoreCase = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to ignore case when completing commands and file names";
};
autoIndent = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to automatically indent new lines based on the previous line";
};
extraPostConfig = lib.mkOption {
type = lib.types.str;
default = "";
description = "Additional configuration to append to the shed configuration file";
};
extraPreConfig = lib.mkOption {
type = lib.types.str;
default = "";
description = "Additional configuration to prepend to the shed configuration file";
};
extraPostConfig = lib.mkOption {
type = lib.types.str;
default = "";
description = "Additional configuration to append to the shed configuration file";
};
extraPreConfig = lib.mkOption {
type = lib.types.str;
default = "";
description = "Additional configuration to prepend to the shed configuration file";
};
}