I am new to zsh and recently moved on from csh, due to obvious reasons.

Oddly enough, its taking me slightly longer than I expected to port a lot of aliases which I use extensively. Here's one of them.

In my csh i have a "cd test case" as follows

alias cdtc 'cd $TOP/\*/\*/tests/!*'

complete cdtc 'p#1#`/bin/ls -1 $TOP/*/*/tests | perl -lne '"'"'print if $_!~m/\// && $_!~m/^$/'"'"'`#'
  1. I guess the complete command prints a neat little coloured list of options of all test cases in all tests folders in my hierarchy, when I press tab.

  2. Partial matches are honoured. i.e. $> cdtc type_a_ <tab> would show directories beginning only with type_a_, but from all hierarchical locations

  3. While I understand the alias, I don't completely understand that perl expression; but I do know it's mostly related to the list of directory names being pretty and not in a single column. Lack of complete grasp is because I did not compose the alias nor the completion command.

My expectation in zsh

I Expected that the complete command wouldn't be necessary and just the alias would do. I've come across a few online posts which discuss _path_files but I couldn't find anything like _path_dirs.

I would like some pointers.

  • corrected cdtc 'cd $TOP/*/*/tests/!*' Aug 12 '19 at 15:45

Just add this to your ~/.zshrc file and you'll get pretty decent tab completion:

autoload -Uz compinit && compinit -C
bindkey '^I' complete-word

No need to mess around with aliases or functions. If you want to customize how the completion works, see http://zsh.sourceforge.net/Doc/Release/Completion-System.html

Or if you don't want to be bothered figuring out how all these settings interact with each other (which can get quite complex quickly), try my plugin marlonrichert/zsh-autocomplete. It auto-configures Zsh's completion system for a great out-of-the-box experience and gives you real-time completion as you type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.