From fbc1c446529194575d321e6e9ed2dfb00a6a2d57 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 2 Feb 2020 23:32:37 +0100 Subject: [PATCH] Add zsh completion path, completions plugin Added `$XDG_CONFIG_HOME/zsh/completions` to fpath for zsh to source completions from. Any stow modules creating scripts and functions which should be auto-completable can add their own completion scripts to this directory for zsh to automatically pick them up. Add zsh-users/zsh-completions plugin to provide completions for a wide array of applications (e.g. glances, nvm). --- zsh/.config/zsh/.zshenv | 5 +++++ zsh/.config/zsh/.zshrc | 23 +++++++++++------------ zsh/.config/zsh/plugins.zsh | 2 ++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/zsh/.config/zsh/.zshenv b/zsh/.config/zsh/.zshenv index 3b40006..3b4e6ac 100644 --- a/zsh/.config/zsh/.zshenv +++ b/zsh/.config/zsh/.zshenv @@ -18,3 +18,8 @@ if [ -d "$XDG_CONFIG_HOME/zsh/env.d" ]; then done unset _env fi + +# add XDG_CONFIG_HOME/zsh/completions to fpath +# zsh uses it to look for completions; throw all +# completions in these dotfiles in there +fpath=("$XDG_CONFIG_HOME/zsh/completions" $fpath) diff --git a/zsh/.config/zsh/.zshrc b/zsh/.config/zsh/.zshrc index 4c78b84..227a804 100644 --- a/zsh/.config/zsh/.zshrc +++ b/zsh/.config/zsh/.zshrc @@ -4,6 +4,16 @@ CONFDIR="${XDG_CONFIG_HOME:-$HOME/.config}" ZSHCONFDIR="$CONFDIR/zsh" +# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.config/zsh/.zshrc. +# Initialization code that may require console input (password prompts, [y/n] +# confirmations, etc.) must go above this block, everything else may go below. +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 + +# load all plugins +[ -f "$ZSHCONFDIR/plugins.zsh" ] && source "$ZSHCONFDIR/plugins.zsh" + # Set completion style # The following lines were added by compinstall zstyle ':completion:*' completer _complete _ignored _approximate @@ -16,17 +26,6 @@ zstyle :compinstall filename "$ZSHCONFDIR/.zshrc" autoload -Uz compinit zmv compinit -# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.config/zsh/.zshrc. -# Initialization code that may require console input (password prompts, [y/n] -# confirmations, etc.) must go above this block, everything else may go below. -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 - - -# load all plugins -[ -f "$ZSHCONFDIR/plugins.zsh" ] && source "$ZSHCONFDIR/plugins.zsh" - # shellcheck source=alias [ -f "$CONFDIR/sh/alias" ] && source "$CONFDIR/sh/alias" # load additional aliases @@ -53,7 +52,7 @@ ENABLE_CORRECTION="true" # Speed up autocomplete, force prefix mapping zstyle ':completion:*' accept-exact '*(N)' zstyle ':completion:*' use-cache on -zstyle ':completion:*' cache-path "${XDG_CACHE_HOME:-$HOME/.cache}/zshcompcache" +zstyle ':completion:*' cache-path "${XDG_CACHE_HOME:-$HOME/.cache}/zshcompcache" # shellcheck disable=SC2016 zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)*==34=34}:${(s.:.)LS_COLORS}")' diff --git a/zsh/.config/zsh/plugins.zsh b/zsh/.config/zsh/plugins.zsh index 6be2450..ff21c78 100644 --- a/zsh/.config/zsh/plugins.zsh +++ b/zsh/.config/zsh/plugins.zsh @@ -58,6 +58,8 @@ load_plugins() { zgen oh-my-zsh plugins/colored-man-pages + zgen load zsh-users/zsh-completions + # Load me last GENCOMPL_FPATH=${XDG_CONFIG_HOME:-"$HOME/.config/zsh"}/complete