bash: format using nixfmt

PR #3609
This commit is contained in:
Lin Jian 2023-01-21 18:27:05 +08:00 committed by Robert Helgesson
parent 8f39c67c4c
commit bb4b25b302
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
2 changed files with 69 additions and 85 deletions

1
format
View file

@ -21,7 +21,6 @@ find . -name '*.nix' \
! -path ./modules/lib/default.nix \ ! -path ./modules/lib/default.nix \
! -path ./modules/lib/file-type.nix \ ! -path ./modules/lib/file-type.nix \
! -path ./modules/misc/news.nix \ ! -path ./modules/misc/news.nix \
! -path ./modules/programs/bash.nix \
! -path ./modules/programs/ssh.nix \ ! -path ./modules/programs/ssh.nix \
! -path ./modules/programs/zsh.nix \ ! -path ./modules/programs/zsh.nix \
! -path ./tests/default.nix \ ! -path ./tests/default.nix \

View file

@ -6,16 +6,15 @@ let
cfg = config.programs.bash; cfg = config.programs.bash;
writeBashScript = name: text: pkgs.writeTextFile { writeBashScript = name: text:
pkgs.writeTextFile {
inherit name text; inherit name text;
checkPhase = '' checkPhase = ''
${pkgs.stdenv.shellDryRun} "$target" ${pkgs.stdenv.shellDryRun} "$target"
''; '';
}; };
in in {
{
meta.maintainers = [ maintainers.rycee ]; meta.maintainers = [ maintainers.rycee ];
imports = [ imports = [
@ -70,20 +69,18 @@ in
}; };
historyControl = mkOption { historyControl = mkOption {
type = types.listOf (types.enum [ type =
"erasedups" types.listOf (types.enum [ "erasedups" "ignoredups" "ignorespace" ]);
"ignoredups" default = [ ];
"ignorespace"
]);
default = [];
description = "Controlling how commands are saved on the history list."; description = "Controlling how commands are saved on the history list.";
}; };
historyIgnore = mkOption { historyIgnore = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = []; default = [ ];
example = [ "ls" "cd" "exit" ]; example = [ "ls" "cd" "exit" ];
description = "List of commands that should not be saved to the history list."; description =
"List of commands that should not be saved to the history list.";
}; };
shellOptions = mkOption { shellOptions = mkOption {
@ -103,10 +100,7 @@ in
# Warn if closing shell with running jobs. # Warn if closing shell with running jobs.
"checkjobs" "checkjobs"
]; ];
example = [ example = [ "extglob" "-cdspell" ];
"extglob"
"-cdspell"
];
description = '' description = ''
Shell options to set. Prefix an option with Shell options to set. Prefix an option with
<quote><literal>-</literal></quote> to unset. <quote><literal>-</literal></quote> to unset.
@ -114,7 +108,7 @@ in
}; };
sessionVariables = mkOption { sessionVariables = mkOption {
default = {}; default = { };
type = types.attrs; type = types.attrs;
example = { MAILCHECK = 30; }; example = { MAILCHECK = 30; };
description = '' description = ''
@ -123,7 +117,7 @@ in
}; };
shellAliases = mkOption { shellAliases = mkOption {
default = {}; default = { };
type = types.attrsOf types.str; type = types.attrsOf types.str;
example = literalExpression '' example = literalExpression ''
{ {
@ -175,36 +169,28 @@ in
}; };
}; };
config = ( config = let
let aliasesStr = concatStringsSep "\n"
aliasesStr = concatStringsSep "\n" ( (mapAttrsToList (k: v: "alias ${k}=${escapeShellArg v}")
mapAttrsToList (k: v: "alias ${k}=${escapeShellArg v}") cfg.shellAliases cfg.shellAliases);
);
shoptsStr = let shoptsStr = let switch = v: if hasPrefix "-" v then "-u" else "-s";
switch = v: if hasPrefix "-" v then "-u" else "-s"; in concatStringsSep "\n"
in concatStringsSep "\n" ( (map (v: "shopt ${switch v} ${removePrefix "-" v}") cfg.shellOptions);
map (v: "shopt ${switch v} ${removePrefix "-" v}") cfg.shellOptions
);
sessionVarsStr = config.lib.shell.exportAll cfg.sessionVariables; sessionVarsStr = config.lib.shell.exportAll cfg.sessionVariables;
historyControlStr = historyControlStr = concatStringsSep "\n"
concatStringsSep "\n" (mapAttrsToList (n: v: "${n}=${v}") ( (mapAttrsToList (n: v: "${n}=${v}") ({
{
HISTFILESIZE = toString cfg.historyFileSize; HISTFILESIZE = toString cfg.historyFileSize;
HISTSIZE = toString cfg.historySize; HISTSIZE = toString cfg.historySize;
} } // optionalAttrs (cfg.historyFile != null) {
// optionalAttrs (cfg.historyFile != null) { HISTFILE = ''"${cfg.historyFile}"'';
HISTFILE = "\"${cfg.historyFile}\""; } // optionalAttrs (cfg.historyControl != [ ]) {
}
// optionalAttrs (cfg.historyControl != []) {
HISTCONTROL = concatStringsSep ":" cfg.historyControl; HISTCONTROL = concatStringsSep ":" cfg.historyControl;
} } // optionalAttrs (cfg.historyIgnore != [ ]) {
// optionalAttrs (cfg.historyIgnore != []) {
HISTIGNORE = escapeShellArg (concatStringsSep ":" cfg.historyIgnore); HISTIGNORE = escapeShellArg (concatStringsSep ":" cfg.historyIgnore);
} }));
));
in mkIf cfg.enable { in mkIf cfg.enable {
home.file.".bash_profile".source = writeBashScript "bash_profile" '' home.file.".bash_profile".source = writeBashScript "bash_profile" ''
# include .profile if it exists # include .profile if it exists
@ -249,6 +235,5 @@ in
home.file.".bash_logout" = mkIf (cfg.logoutExtra != "") { home.file.".bash_logout" = mkIf (cfg.logoutExtra != "") {
source = writeBashScript "bash_logout" cfg.logoutExtra; source = writeBashScript "bash_logout" cfg.logoutExtra;
}; };
} };
);
} }