From 0068a4aee656a7f2c2612765e241657aba503c33 Mon Sep 17 00:00:00 2001 From: 0xrsydn Date: Sun, 28 Sep 2025 02:20:02 +0700 Subject: [PATCH] reprogram zsh configs --- modules/home/rsydn/base.nix | 30 ------------------------------ modules/home/rsydn/shell/zsh.nix | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/modules/home/rsydn/base.nix b/modules/home/rsydn/base.nix index 2e4e255..18f0677 100644 --- a/modules/home/rsydn/base.nix +++ b/modules/home/rsydn/base.nix @@ -15,36 +15,6 @@ enableVimMode = true; powerlevel10kConfigFile = ./shell/p10k.zsh; aliases = { ll = "ls -alF"; }; - extraAfter = '' - function rsydn-accept-autosuggest-or-complete() { - local original_buffer=$BUFFER - local original_cursor=$CURSOR - zle autosuggest-accept 2>/dev/null - if [[ $BUFFER == "$original_buffer" && $CURSOR -eq $original_cursor ]]; then - zle expand-or-complete - fi - } - zle -N rsydn-accept-autosuggest-or-complete - function rsydn-bind-tab-autosuggest() { - bindkey '^I' rsydn-accept-autosuggest-or-complete 2>/dev/null || true - bindkey -M viins '^I' rsydn-accept-autosuggest-or-complete 2>/dev/null || true - } - function rsydn-ensure-tab-autosuggest() { - local default_binding - default_binding=$(bindkey '^I' 2>/dev/null || true) - if [[ $default_binding != *rsydn-accept-autosuggest-or-complete* ]]; then - rsydn-bind-tab-autosuggest - fi - local viins_binding - viins_binding=$(bindkey -M viins '^I' 2>/dev/null || true) - if [[ $viins_binding != *rsydn-accept-autosuggest-or-complete* ]]; then - bindkey -M viins '^I' rsydn-accept-autosuggest-or-complete 2>/dev/null || true - fi - } - autoload -Uz add-zsh-hook - add-zsh-hook precmd rsydn-ensure-tab-autosuggest - rsydn-ensure-tab-autosuggest - ''; }; programs.git.enable = true; diff --git a/modules/home/rsydn/shell/zsh.nix b/modules/home/rsydn/shell/zsh.nix index 110ee6f..45a3282 100644 --- a/modules/home/rsydn/shell/zsh.nix +++ b/modules/home/rsydn/shell/zsh.nix @@ -57,6 +57,21 @@ in { description = "Enable zsh-autosuggestions."; }; + autosuggestAcceptWidgets = mkOption { + type = types.listOf types.str; + default = [ + "forward-char" + "end-of-line" + "vi-forward-char" + "vi-end-of-line" + "vi-add-eol" + "expand-or-complete" + "complete-word" + "fzf-completion" + ]; + description = "Widgets that should accept autosuggestions before running (ZSH_AUTOSUGGEST_ACCEPT_WIDGETS)."; + }; + enableSyntaxHighlighting = mkOption { type = types.bool; default = true; @@ -79,6 +94,9 @@ in { syntaxHighlighting.enable = cfg.enableSyntaxHighlighting; shellAliases = cfg.aliases; initContent = lib.mkAfter cfg.extraAfter; + localVariables = lib.mkIf cfg.enableAutoSuggestion { + ZSH_AUTOSUGGEST_ACCEPT_WIDGETS = cfg.autosuggestAcceptWidgets; + }; }; } { programs.zsh.initContent = lib.mkOrder 550 cfg.extraBeforeCompInit; }