2021-02-19 20:44:18 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
2021-03-13 01:02:50 +01:00
|
|
|
let
|
|
|
|
cfg = config.my.home.zsh;
|
2023-03-08 15:36:27 +01:00
|
|
|
|
|
|
|
# Have a nice relative path for XDG_CONFIG_HOME, without leading `/`
|
|
|
|
relativeXdgConfig =
|
|
|
|
let
|
|
|
|
noHome = lib.removePrefix config.home.homeDirectory;
|
|
|
|
noSlash = lib.removePrefix "/";
|
|
|
|
in
|
|
|
|
noSlash (noHome config.xdg.configHome);
|
2021-03-13 01:02:50 +01:00
|
|
|
in
|
2021-02-19 19:44:09 +01:00
|
|
|
{
|
2023-02-22 17:00:26 +01:00
|
|
|
options.my.home.zsh = with lib; {
|
|
|
|
enable = my.mkDisableOption "zsh configuration";
|
2023-02-22 17:04:20 +01:00
|
|
|
|
2023-02-22 17:09:45 +01:00
|
|
|
launchTmux = mkEnableOption "auto launch tmux at shell start";
|
2023-08-13 17:19:47 +02:00
|
|
|
|
|
|
|
notify = {
|
|
|
|
enable = mkEnableOption "zsh-done notification";
|
|
|
|
|
2024-02-15 17:33:27 +01:00
|
|
|
exclude = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [
|
|
|
|
"direnv reload"
|
|
|
|
"fg"
|
|
|
|
"git (?!push|pull|fetch)"
|
|
|
|
"htop"
|
|
|
|
"less"
|
|
|
|
"man"
|
|
|
|
"nvim"
|
|
|
|
"tail -f"
|
|
|
|
"tmux"
|
|
|
|
"vim"
|
|
|
|
];
|
|
|
|
example = [ "command --long-running-option" ];
|
|
|
|
description = ''
|
|
|
|
List of exclusions which should not be create a notification. Accepts
|
|
|
|
Perl regexes (implicitly anchored with `^\s*`).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-08-13 17:19:47 +02:00
|
|
|
ssh = {
|
|
|
|
enable = mkEnableOption "notify through SSH/non-graphical connections";
|
|
|
|
|
|
|
|
useOsc777 = lib.my.mkDisableOption "use OSC-777 for notifications";
|
|
|
|
};
|
|
|
|
};
|
2021-03-13 01:02:50 +01:00
|
|
|
};
|
|
|
|
|
2023-08-13 16:59:25 +02:00
|
|
|
config = lib.mkIf cfg.enable (lib.mkMerge [
|
|
|
|
{
|
|
|
|
home.packages = with pkgs; [
|
|
|
|
zsh-completions
|
|
|
|
];
|
2022-03-02 17:01:11 +01:00
|
|
|
|
2023-08-13 16:59:25 +02:00
|
|
|
programs.zsh = {
|
|
|
|
enable = true;
|
|
|
|
dotDir = "${relativeXdgConfig}/zsh"; # Don't clutter $HOME
|
|
|
|
enableCompletion = true;
|
2021-02-19 19:44:09 +01:00
|
|
|
|
2023-08-13 16:59:25 +02:00
|
|
|
history = {
|
|
|
|
size = 500000;
|
|
|
|
save = 500000;
|
|
|
|
extended = true;
|
|
|
|
expireDuplicatesFirst = true;
|
|
|
|
ignoreSpace = true;
|
|
|
|
ignoreDups = true;
|
|
|
|
share = false;
|
|
|
|
path = "${config.xdg.dataHome}/zsh/zsh_history";
|
|
|
|
};
|
2021-02-19 19:44:09 +01:00
|
|
|
|
2023-08-13 16:59:25 +02:00
|
|
|
plugins = [
|
|
|
|
{
|
|
|
|
name = "fast-syntax-highlighting";
|
|
|
|
file = "share/zsh/site-functions/fast-syntax-highlighting.plugin.zsh";
|
|
|
|
src = pkgs.zsh-fast-syntax-highlighting;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "agkozak-zsh-prompt";
|
|
|
|
file = "share/zsh/site-functions/agkozak-zsh-prompt.plugin.zsh";
|
|
|
|
src = pkgs.agkozak-zsh-prompt;
|
|
|
|
}
|
|
|
|
];
|
2021-02-19 20:05:15 +01:00
|
|
|
|
2023-08-13 16:59:25 +02:00
|
|
|
# Modal editing is life, but CLI benefits from emacs gymnastics
|
|
|
|
defaultKeymap = "emacs";
|
2021-02-19 20:16:08 +01:00
|
|
|
|
2023-08-13 16:59:25 +02:00
|
|
|
# Make those happen early to avoid doing double the work
|
2023-08-13 17:05:27 +02:00
|
|
|
initExtraFirst = lib.mkBefore ''
|
2023-08-13 16:59:25 +02:00
|
|
|
${
|
|
|
|
lib.optionalString cfg.launchTmux ''
|
|
|
|
# Launch tmux unless already inside one
|
|
|
|
if [ -z "$TMUX" ]; then
|
|
|
|
exec tmux new-session
|
|
|
|
fi
|
|
|
|
''
|
|
|
|
}
|
|
|
|
'';
|
2021-09-30 15:34:16 +02:00
|
|
|
|
2023-08-13 17:05:27 +02:00
|
|
|
initExtra = lib.mkAfter ''
|
2023-08-13 16:59:25 +02:00
|
|
|
source ${./completion-styles.zsh}
|
|
|
|
source ${./extra-mappings.zsh}
|
|
|
|
source ${./options.zsh}
|
2023-02-08 15:44:20 +01:00
|
|
|
|
2023-08-13 16:59:25 +02:00
|
|
|
# Source local configuration
|
|
|
|
if [ -f "$ZDOTDIR/zshrc.local" ]; then
|
|
|
|
source "$ZDOTDIR/zshrc.local"
|
|
|
|
fi
|
|
|
|
'';
|
2021-02-19 21:56:21 +01:00
|
|
|
|
2023-08-13 16:59:25 +02:00
|
|
|
localVariables = {
|
|
|
|
# I like having the full path
|
|
|
|
AGKOZAK_PROMPT_DIRTRIM = 0;
|
|
|
|
# Because I *am* from EPITA
|
|
|
|
AGKOZAK_PROMPT_CHAR = [ "42sh$" "42sh#" ":" ];
|
|
|
|
# Easy on the eyes
|
|
|
|
AGKOZAK_COLORS_BRANCH_STATUS = "magenta";
|
|
|
|
# I don't like moving my eyes
|
|
|
|
AGKOZAK_LEFT_PROMPT_ONLY = 1;
|
|
|
|
};
|
2021-03-30 23:33:42 +02:00
|
|
|
|
2023-08-13 16:59:25 +02:00
|
|
|
# Enable VTE integration
|
|
|
|
enableVteIntegration = true;
|
|
|
|
};
|
|
|
|
}
|
2023-08-13 17:19:47 +02:00
|
|
|
|
|
|
|
(lib.mkIf cfg.notify.enable {
|
|
|
|
programs.zsh = {
|
|
|
|
plugins = [
|
|
|
|
{
|
|
|
|
name = "zsh-done";
|
|
|
|
file = "share/zsh/site-functions/done.plugin.zsh";
|
|
|
|
src = pkgs.ambroisie.zsh-done;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
# `localVariables` values don't get merged correctly due to their type,
|
|
|
|
# don't use `mkIf`
|
2024-02-15 17:33:27 +01:00
|
|
|
localVariables = {
|
|
|
|
DONE_EXCLUDE =
|
|
|
|
let
|
|
|
|
joined = lib.concatMapStringsSep "|" (c: "(${c})") cfg.notify.exclude;
|
|
|
|
in
|
|
|
|
''^\s*(${joined})'';
|
|
|
|
}
|
|
|
|
# Enable `zsh-done` through SSH, if configured
|
|
|
|
// lib.optionalAttrs cfg.notify.ssh.enable {
|
|
|
|
DONE_ALLOW_NONGRAPHICAL = 1;
|
|
|
|
};
|
2023-08-13 17:19:47 +02:00
|
|
|
|
|
|
|
# Use OSC-777 to send the notification through SSH
|
|
|
|
initExtra = lib.mkIf cfg.notify.ssh.useOsc777 ''
|
|
|
|
done_send_notification() {
|
|
|
|
local exit_status="$1"
|
|
|
|
local title="$2"
|
|
|
|
local message="$3"
|
|
|
|
|
|
|
|
${lib.getExe pkgs.ambroisie.osc777} "$title" "$message"
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
})
|
2023-08-13 16:59:25 +02:00
|
|
|
]);
|
2021-02-19 19:44:09 +01:00
|
|
|
}
|