2

I have the following alias in my ~/.zshrc:

~ which pulseaudio-restart 
pulseaudio-restart: aliased to killall pulseaudio && pulseaudio --start

Is it possible to configure Zsh in a way that typing restart will output me pulseaudio-restart as a suggestion since it contains the string restart?

Currently, typing restart only brings up:

~ rest
restart        restore-trash
orschiro
  • 19,847
  • 19
  • 64
  • 95
  • Why don't you name the alias `restart-pulseaudio`? Since you are using tab completion, it doesn't appear that the exact name of the alias matters that much. – chepner May 05 '14 at 15:07
  • Good point. However, for me it is easier to remember `pulseaudio-restart` because I know that I am looking for a command related to `pulseaudio`. – orschiro May 05 '14 at 18:58

1 Answers1

3

Yes it is possible. For this you have to set/modify the matcher-list style for the completion module. This can be done with the following command:

zstyle ':completion:*' matcher-list 'l:|=* r:|=*' 

This tells the completion to look for completion on the left as well as on the right side of the typed word (specifics can be found in zshcompwid(1)).

As the name matcher-list indicates, there may be more than one match specification, in which case it is important that 'l:|=* r:|=*' is the first one. The specifications are tried in the order they appear until something returns a match.


For oh-my-zsh the matcher-list is set in lib/completion.zsh and it already contains the required specification, but only as the last option. You can either change the order there or add your own settings in ~/.zshrc after oh-my-zsh is loaded.

Adaephon
  • 16,929
  • 1
  • 54
  • 71
  • Very nice solution! Although I do use `oh-my-zsh`, I just added `zstyle ':completion:*' matcher-list 'l:|=* r:|=*'` to the bottom of my `~/.zshrc` and it works perfectly! – orschiro May 02 '14 at 18:25