nixos-config/configurations/profile/home/shell/zsh.nix

126 lines
3.3 KiB
Nix
Raw Normal View History

2024-02-25 22:30:13 +01:00
{ config, pkgs, lib, materusArg, ... }:
2023-10-08 11:42:08 +02:00
let
2024-02-26 01:23:15 +01:00
relToDotDir = file: (lib.optionalString (config.programs.zsh.dotDir != null) (config.programs.zsh.dotDir + "/")) + file;
2024-03-11 16:19:31 +01:00
pluginsDir =
if config.programs.zsh.dotDir != null then
2024-03-21 18:55:50 +01:00
relToDotDir "plugins" else "${config.home.homeDirectory}/.zsh/plugins";
2024-02-26 01:23:15 +01:00
2023-10-08 11:42:08 +02:00
p10kcfg = "${zshcfg}/p10kcfg";
zshcfg = "${materusArg.cfg.path}" + "/extraFiles/config/zsh";
2023-10-08 11:42:08 +02:00
cfg = config.materus.profile.zsh;
2024-02-26 01:23:15 +01:00
#enableStarship = config.materus.starship.enable;
makeEnv = name: val: ''${name}=''${${name}:-"${val}"}'';
makeIfVar = var: val: ret: ''
2024-03-11 16:19:31 +01:00
if [ ''$${var} = "${val}" ]; then
${ret}
fi'';
2024-02-26 01:23:15 +01:00
2024-03-11 16:19:31 +01:00
makePlugin = nameArg: fileArg: srcArg: rec {
2024-02-26 01:23:15 +01:00
name = nameArg;
src = srcArg;
path = pluginsDir + "/" + name;
file = fileArg;
fullPath = path + "/" + file;
};
extraPlugins = {
powerlevel10k = makePlugin "powerlevel10k" "powerlevel10k.zsh-theme" (pkgs.fetchFromGitHub {
2024-03-11 16:19:31 +01:00
owner = "romkatv";
repo = "powerlevel10k";
rev = "v1.20.0";
sha256 = "sha256-ES5vJXHjAKw/VHjWs8Au/3R+/aotSbY7PWnWAMzCR8E=";
});
2024-02-26 01:23:15 +01:00
};
2023-10-08 11:42:08 +02:00
in
{
options.materus.profile.zsh.enable = materusArg.pkgs.lib.mkBoolOpt config.materus.profile.enableTerminalExtra "Enable materus zsh config";
2023-10-08 11:42:08 +02:00
options.materus.profile.zsh.prompt = lib.mkOption {
2024-03-11 16:19:31 +01:00
type = lib.types.enum [ "p10k" "starship" ];
example = "p10k";
default = "p10k";
2023-10-08 11:42:08 +02:00
};
config = lib.mkIf cfg.enable {
home.packages = [
pkgs.ripgrep
];
2024-03-11 16:19:31 +01:00
home.file = builtins.foldl' (a: b: a // b) { } (builtins.map (plugin: { ${plugin.path}.source = plugin.src; }) (builtins.attrValues extraPlugins));
2023-10-08 11:42:08 +02:00
programs.zsh = {
enable = true;
enableAutosuggestions = true;
enableSyntaxHighlighting = true;
2023-10-08 11:42:08 +02:00
enableVteIntegration = true;
historySubstringSearch.enable = true;
historySubstringSearch.searchUpKey = ";5A";
historySubstringSearch.searchDownKey = ";5B";
envExtra = ''
2024-03-11 16:19:31 +01:00
${makeEnv "__MATERUS_HM_ZSH" "1"}
${makeEnv "__MATERUS_HM_ZSH_PROMPT" cfg.prompt}
2023-10-08 11:42:08 +02:00
'';
2024-02-26 01:23:15 +01:00
initExtraFirst = ''
${makeIfVar "__MATERUS_HM_ZSH_PROMPT" "p10k" ''
if [[ -r "''${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-''${(%):-%n}.zsh" ]]; then
source "''${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-''${(%):-%n}.zsh"
fi
if [[ -f "${extraPlugins.powerlevel10k.fullPath}" ]]; then
source "${extraPlugins.powerlevel10k.fullPath}"
fi
''
}'';
2023-10-08 11:42:08 +02:00
plugins = [
];
2024-03-11 16:19:31 +01:00
2023-10-08 11:42:08 +02:00
history = {
extended = true;
save = 100000;
size = 100000;
share = false;
ignoreDups = true;
ignoreSpace = true;
};
initExtra = ''
. ${zshcfg}/zinputrc
source ${zshcfg}/zshcompletion.zsh
bindkey -r "^["
bindkey ";5C" forward-word
bindkey ";5D" backward-word
2024-03-11 16:19:31 +01:00
'' +
makeIfVar "__MATERUS_HM_ZSH_PROMPT" "p10k" ''
2023-10-08 11:42:08 +02:00
if zmodload zsh/terminfo && (( terminfo[colors] >= 256 )); then
[[ ! -f ${p10kcfg}/fullcolor.zsh ]] || source ${p10kcfg}/fullcolor.zsh
else
[[ ! -f ${p10kcfg}/compatibility.zsh ]] || source ${p10kcfg}/compatibility.zsh
fi
2024-02-26 01:23:15 +01:00
'';
2023-10-08 11:42:08 +02:00
};
2024-03-17 10:25:09 +01:00
programs.starship.enableZshIntegration = lib.mkDefault false;
2023-10-08 11:42:08 +02:00
};
}