Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: _pick_variant



On Fri, Nov 13, 2020 at 11:42 AM Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> wrote:
The first solution can be generalized:

    () {
      local k v
      for k v in "${(kv)_comps[@]}"; do
        if [[ ${functions_source[$k]:-$commands[$k]} == ~/* &&
              $functions_source[$v] != ~/* ]]; then
          _comps[$k]=_default
        fi
      done
    }

This will disable programmable completions for all commands and
functions defined under $HOME that don't have their own completions.
If you have compdef calls in your dotfiles, you'll need to move them
below this stanza.

If anyone wants to use this, beware that it may increase zsh startup time. On a raspberry pi -- the slowest machine I've tested this on -- it takes 45ms. Here's a faster version that does the same thing. As is often the case with optimized zsh, it's unreadable.

  () {
    emulate -L zsh -o extended_glob
    local cmd MATCH MBEGIN MEND
    for cmd in ${${(M)${(k)_comps:/(#m)*/${${functions_source[$MATCH]:+$functions_source[$MATCH]/$MATCH}:-$commands[$MATCH]}}:#~/*}:t}; do
      if [[ $functions_source[$_comps[$cmd]] != ~/* ]]; then
        _comps[$cmd]=_default
      fi
    done
    fi
  }

Roman. 


Messages sorted by: Reverse Date, Date, Thread, Author