2023-09-02 15:33:36 +02:00
{ config , pkgs , . . . }:
2023-11-23 11:09:32 +01:00
let
2025-01-06 16:05:58 +01:00
# https://nixos.wiki/wiki/Zsh
2023-11-23 11:09:32 +01:00
zsh-config = {
enable = true ;
2025-01-06 16:05:58 +01:00
autosuggestion . enable = true ;
syntaxHighlighting . enable = true ;
2023-11-23 11:09:32 +01:00
shellAliases = {
#ll = "ls -l";
#update = "sudo nixos-rebuild switch";
} ;
2025-01-06 16:05:58 +01:00
# Keep a detailed history to analyse it later:
# https://github.com/bamos/zsh-history-analysis/blob/master/README.md
#
# View tail of history:
# history -i -10
#
# Keep a long history (for later analysis).
history . size = 100000 ;
# Record datetime time of commands (for later analysis).
# Instead of just `ls`, this will store e.g. `: 1736166069:0;ls`.
history . extended = true ;
# Do not record an event that was just recorded again.
history . ignoreDups = false ;
# Delete an old recorded event if a new event is a duplicate.
history . ignoreAllDups = false ;
# Do not record if first char is space.
history . ignoreSpace = true ;
# Share between sessions.
2025-01-06 16:48:09 +01:00
# This implies INC_APPEND_HISTORY which records commands as soon as they are entered, rather than waiting until the shell exits.
# https://zsh.sourceforge.io/Doc/Release/Options.html
2025-01-06 16:05:58 +01:00
history . share = true ;
2025-01-06 16:48:09 +01:00
# Don't record commands if they match one of the given shell patterns.
# Only in zsh grouping (`(a|b)`) is available: https://thevaluable.dev/zsh-expansion-guide-example/
# TODO: Somehow HISTORY_IGNORE is missing in my zsh config. https://github.com/nix-community/home-manager/blob/613691f285dad87694c2ba1c9e6298d04736292d/modules/programs/zsh.nix#L680
history . ignorePatterns = [ " ( c d | l s ) ( . / | . . / ) * " " p w d " " l s " " c d " ] ;
2023-11-23 11:09:32 +01:00
oh-my-zsh = {
enable = true ;
plugins = [
# Provides many aliases and a few useful functions.
#"git"
# Easily prefix your current or previous commands with sudo by pressing `esc` twice.
#"sudo"
] ;
#theme = "robbyrussell";
2025-01-06 16:48:09 +01:00
theme = " a g n o s t e r " ; # If in a Git directory, adds the branch to the shell promt.
2023-11-23 11:09:32 +01:00
} ;
} ;
in
2023-09-02 15:33:36 +02:00
{
2023-09-06 14:02:19 +02:00
# https://nixos.wiki/wiki/Command_Shell
2025-01-06 16:05:58 +01:00
# When adding a new shell, always enable the shell system-wide, even if it's already enabled in your Home Manager configuration, otherwise it won't source the necessary files.
2023-09-06 14:02:19 +02:00
programs . zsh . enable = true ;
users . defaultUserShell = pkgs . zsh ;
2023-09-05 17:56:38 +02:00
# Inside the following Home Manager configuration block,
# `config` refers to Home Manager configuration.
home-manager . users . yoda = { osConfig , config , pkgs , . . . }: {
2023-11-23 11:09:32 +01:00
programs . zsh = zsh-config // {
2023-09-05 17:56:38 +02:00
# nix-repl: config.home-manager.users.yoda.programs.zsh.history.path
2023-11-23 11:09:32 +01:00
# -> ~/.local/share/.histfile
history . path = " ${ config . xdg . dataHome } / . h i s t f i l e " ;
} ;
} ;
home-manager . users . root = { osConfig , config , pkgs , . . . }: {
programs . zsh = zsh-config // {
2023-09-05 17:56:38 +02:00
history . path = " ${ config . xdg . dataHome } / . h i s t f i l e " ;
2023-09-02 15:33:36 +02:00
} ;
} ;
}