Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Notifications
Mark all as read
Q&A

Case independent tab completion in zsh shell

+6
−0

I'm using a zsh shell with

zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
autoload -Uz compinit && compinit

to allow tab completion regardless of capitalisation, e.g. cd desk will be completed to cd Desktop

However using autoload -Uz compinit && compinit has a strange side effect. Let's assume I have a folder with the two files

test.dtx 
test.tex

If I start to write latex te and press tab, it will automatically complete to latex test.tex instead of suggesting me both files. For other commands, e.g. ls te, the tab completion will complete to ls test and suggest both files.

Is there any way to make the tab completion independent of capitalisation while still getting suggested all files?

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

ZSH completion definitions can apply a file name pattern/mask to restrict which files are suggested (5 comments)

1 answer

+3
−0

zsh comes with a number of completion function files for popular programs and commands that govern how completions and suggestions are executed in relation to these programs/commands.

autoload -Uz compinit && compinit is basically just a way to load and initialize these completion functions[1].

One feature of such completion function is the ability to constrain file suggestions for the respective program/command based on file name patterns, so as to not suggest files that the respective program/command won't be able to consume.

Unfortunately, the completion function for latex[2] is missing the dtx file extension in its file name pattern *.(tex|TEX|texinfo|texi)(-.), and thus dtx files will not be suggested for latex.


Update: As per this comment, future versions of zsh will include the dtx file extension in the file name pattern for the latex completion function, thus the solutions/workarounds described below shouldn't be necessary anymore with respect to future zsh releases/updates.


As samcarter themselves found out (link to comment), for making zsh suggest all files for latex, it is sufficient to remove the entry for the latex completion function from the ".zcompdump" file. Alternatively, the latex completion function file ("_tex") might be removed from the directory with the completion function files, or renamed to a file name that does not start with an underscore[3]. It has to be seen, though, whether such measures will survive a possible future update of the zsh installation.


  1. compinit in the zsh documentation: https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Use-of-compinit ↩︎

  2. Source in zsh's git repository:https://sourceforge.net/p/zsh/code/ci/master/tree/Completion/Unix/Command/_tex ↩︎

  3. By convention, only completion function files starting with an underscore are autoloaded. (https://zsh.sourceforge.io/Doc/Release/Completion-System.html#Autoloaded-files) ↩︎

Why does this post require moderator attention?
You might want to add some details to your flag.

2 comment threads

Update (1 comment)
Thanks a lot for writing the answer! (2 comments)

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!

Like what we're doing? Support us! Donate