Ubuntu – How to iterate over shell function completions and alias completions before external command completions in zsh

auto-completioncommand linezsh

As it stands when I hit TAB to iterate over possible completions for a partial command external command completions are iterated first:

user@user-X550CL ~ % apt
Completing external command
apt                       aptd                      apt-key                 
apt-add-repository        aptdcon                   apt-mark                
apt-cache                 apt-extracttemplates      apt-sortpkgs            
apt-cdrom                 apt-ftparchive            apturl                  
apt-config                apt-get                   apturl-gtk              
Completing shell function
apt-get_all
Completing alias
apt-get_autoremove_clean  apt-get_update            apt-get_update_upgrade 

In the above example it'd took 17 more hit on TAB to get to apt-get_autoremove_clean (or to type an additional -get_ and to hit TAB 3 more times).

In most cases I'd find it way more convenient if shell functions and aliases would be iterated first.

Is there a way to setup zsh to iterate over shell functions and aliases first?

Best Answer

Looking at the docs, this might do the trick:

$ zstyle ':completion:*:*:-command-:*' group-order aliases functions commands
$ sudo<tab>
sudoa
sudof
sudo        sudoedit    sudoreplay

(In case it's not obvious, sudoa is an alias and sudof is a function.)