1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-20 10:09:45 +01:00

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/file-type.nix \
! -path ./modules/misc/news.nix \
! -path ./modules/programs/bash.nix \
! -path ./modules/programs/ssh.nix \
! -path ./modules/programs/zsh.nix \
! -path ./tests/default.nix \

View file

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