diff --git a/modules/core/user.nix b/modules/core/user.nix index 14b04ff..00098b5 100644 --- a/modules/core/user.nix +++ b/modules/core/user.nix @@ -9,6 +9,7 @@ }: let shellCfg = config.modules.shell; + zshCfg = config.modules.zsh; in { imports = [ inputs.home-manager.nixosModules.home-manager ]; @@ -52,5 +53,10 @@ in # Set /etc/shells so GDM will show our user when ZSH is selected environment.shells = [ pkgs.${shellCfg.defaultShell} ]; + # Needed to get completion for system packages (e.g. systemd) + environment.pathsToLink = + [ ] + ++ (if zshCfg.enable then [ "/share/zsh" ] else [ ]); + nix.settings.allowed-users = [ "${username}" ]; } diff --git a/modules/home/zsh/completion.nix b/modules/home/zsh/completion.nix new file mode 100644 index 0000000..f4fbb02 --- /dev/null +++ b/modules/home/zsh/completion.nix @@ -0,0 +1,18 @@ +{ + config, + lib, + osConfig, + ... +}: +with lib; +let + cfg = osConfig.modules.zsh; + xdgCfg = config.xdg; +in +{ + config = mkIf cfg.enable { + home.file."${xdgCfg.configHome}/zsh/completion.zsh" = { + source = ./completion.zsh; + }; + }; +} diff --git a/modules/home/zsh/completion.zsh b/modules/home/zsh/completion.zsh new file mode 100644 index 0000000..9c6c88b --- /dev/null +++ b/modules/home/zsh/completion.zsh @@ -0,0 +1,20 @@ +# Work with hidden files +_comp_options+=(globdots) + +# Autocomplete cache options +zstyle ':completion:*' use-cache on +zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/.zcompcache" + +# Colors +zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} +# Menu options +zstyle ':completion:*' menu select +zstyle ':completion:*:*:*:*:descriptions' format '%F{green}-- %d --%f' +zstyle ':completion:*:*:*:*:corrections' format '%F{yellow}!- %d (errors: %e) -!%f' +zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f' +zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f' +# Group results +zstyle ':completion:*' group-name '' + +# Autocomplete options +zstyle ':completion:*' completer _extensions _complete _approximate diff --git a/modules/home/zsh/default.nix b/modules/home/zsh/default.nix index 0b77b3b..86943e8 100644 --- a/modules/home/zsh/default.nix +++ b/modules/home/zsh/default.nix @@ -12,6 +12,7 @@ let in { imports = [ + ./completion.nix ./p10k.nix ]; @@ -19,7 +20,7 @@ in enable = cfg.enable; dotDir = "${xdgCfg.configHome}/zsh"; autosuggestion.enable = false; - enableCompletion = true; + enableCompletion = false; syntaxHighlighting = { enable = true; highlighters = [ @@ -53,19 +54,24 @@ in source "${xdgCfg.configHome}/zsh/p10k.zsh"; ''; zshConfig = mkOrder 1000 '' - # vi keybindings for menu select - #bindkey -M menuselect 'h' vi-backward-char - #bindkey -M menuselect 'k' vi-up-line-or-history - #bindkey -M menuselect 'j' vi-down-line-or-history - #bindkey -M menuselect 'l' vi-forward-char + # Autocompletion and menu styling + zmodload zsh/complist + autoload -Uz compinit && compinit + source "${xdgCfg.configHome}/zsh/completion.zsh"; - # Tab to accept current selection - #bindkey -M menuselect '^I' accept-and-infer-next-history + # vi keybindings for menu select + bindkey -M menuselect 'h' vi-backward-char + bindkey -M menuselect 'k' vi-up-line-or-history + bindkey -M menuselect 'j' vi-down-line-or-history + bindkey -M menuselect 'l' vi-forward-char - # Control arrow keys - bindkey '^[[1;5C' forward-word - bindkey '^[[1;5D' backward-word - ''; + # Tab to accept current selection + bindkey -M menuselect '^I' accept-and-infer-next-history + + # Control arrow keys + bindkey '^[[1;5C' forward-word + bindkey '^[[1;5D' backward-word + ''; in mkMerge [ zshConfigInitEarly zshConfig ]; shellAliases = { @@ -85,6 +91,11 @@ in src = "${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/"; file = "powerlevel10k.zsh-theme"; } + { + name = "zsh-autocomplete"; + src = "${pkgs.zsh-autocomplete}/share/zsh-autocomplete/"; + file = "zsh-autocomplete.zsh"; + } ]; }; }