Jan
7
zsh tab completion
Filed Under Technology |
My name is Tony, and I’m a zsh user.
I have been for many years, and have steadfastly withstood the onslaught of upstarts like bash. For the most part I don’t really know whether zsh or bash is ‘better’, I just happen to have a whole series of startup scripts, built up over the last 10 years, that make my environment be the way I want, and that only work with zsh. I’m sure I could do them all in bash, but I don’t really have the time, the energy or the inclination to work out how, when it’s all there for me in zsh. (When I was at university, I would often spend days just working through all the man pages for something, testing all the different options, deciding which I liked best, and setting up my configuration accordingly. Those days are long since past…)
Of course, since I read my way through the zsh docs lots has changed. In particular tab completion has gotten a lot more advanced. I’ve known this for a long time, but have never gotten around to working out how to bring my setup up to date in this regard. Until yesterday, when I finally got fed up, and tried to investigate this.
However, that was harder than it should have been. I could find lots of information on how to build my own completion routines, but I couldn’t actually work out how to just get all the default ones to happen. I eventually found:
The function compinstall can be run by a user to set up the completion system for use, which also provides options for more advanced usage. However, if the system was installed completely, it should be enough to call the shell function compinit from your initialization file.
Well, with a fresh apt-get install zsh from Debian, it doesn’t seem to be “installed completely”. What I eventually worked out I had to do was source /usr/share/zsh/4.0.6/functions/Completion/compinstall, hit return a few times to confirm some things which gave me no options anyway, and then be faced with a menu system that seemed to expect me to be able to answer thousands of questions that I couldn’t possibly know the answers to. I eventually gave up, used ’save and exit’ to write out some new config options to my startup script, and was slightly surprised that everything actually now worked.
So now I finally can tab complete everything sensibly. And I’m even more impressed than I thought I’d be. I knew it would be able to complete hostnames after an ’ssh’ and things like that, but I’d never realised it would do really obvious things like only complete to directories (or symlinked ones) after a ‘cd’. Or that after a chown it’ll tab complete only to valid users of the system. And I’m really impressed that it’ll tab complete to valid debian packages after an ‘apt-get install’.