1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-30 06:59:45 +01:00

zsh: add history.ignorePatterns option (#1933)

The corresponding variable is `HISTORY_IGNORE` described in zshparam(1).
This commit is contained in:
oxalica 2021-05-02 04:33:45 +08:00 committed by GitHub
parent 19fc0917c0
commit 5709b5f953
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View file

@ -60,6 +60,16 @@ let
description = "History file location";
};
ignorePatterns = mkOption {
type = types.listOf types.str;
default = [];
example = literalExample ''[ "rm *" "pkill *" ]'';
description = ''
Do not enter command lines into the history list
if they match any one of the given shell patterns.
'';
};
ignoreDups = mkOption {
type = types.bool;
default = true;
@ -495,6 +505,7 @@ in
# See https://github.com/nix-community/home-manager/issues/177.
HISTSIZE="${toString cfg.history.size}"
SAVEHIST="${toString cfg.history.save}"
${optionalString (cfg.history.ignorePatterns != []) "HISTORY_IGNORE=${lib.escapeShellArg "(${lib.concatStringsSep "|" cfg.history.ignorePatterns})"}"}
${if versionAtLeast config.home.stateVersion "20.03"
then ''HISTFILE="${cfg.history.path}"''
else ''HISTFILE="$HOME/${cfg.history.path}"''}

View file

@ -4,5 +4,6 @@
zsh-history-path-new-custom = ./history-path-new-custom.nix;
zsh-history-path-old-default = ./history-path-old-default.nix;
zsh-history-path-old-custom = ./history-path-old-custom.nix;
zsh-history-ignore-pattern = ./history-ignore-pattern.nix;
zsh-prezto = ./prezto.nix;
}

View file

@ -0,0 +1,21 @@
{ config, lib, pkgs, ... }:
with lib;
{
imports = [
({ ... }: { config.programs.zsh.history.ignorePatterns = [ "echo *" ]; })
({ ... }: { config.programs.zsh.history.ignorePatterns = [ "rm *" ]; })
];
config = {
programs.zsh.enable = true;
nixpkgs.overlays =
[ (self: super: { zsh = pkgs.writeScriptBin "dummy-zsh" ""; }) ];
nmt.script = ''
assertFileContains home-files/.zshrc "HISTORY_IGNORE='(echo *|rm *)'"
'';
};
}