2

I've set up this function in my ~/.zshrc:

cdp() {
  cd "/mnt/c/Users/Mark/PhpstormProjects/$1"
}

But I don't get tab completions for it. Is there any way to get the directory names to autocomplete when I tab?

1 Answer 1

2

Define a completion function for cdp. Conventionally, the function is called _cdp. You can define it in your .zshrc and assign it explicitly with compdef.

_cdp () {
  … # code goes here
}
compdef _cdp cdp

Alternatively, put the completion code in a file in your $fpath called _cdp with a completion autoload directive.

#compdef cdp
… # code goes here

To complete directories, use _files -/. To complete directories relative to a different place from the current directory, use the -W option. Since this function only takes one argument, only complete the first argument.

_cdp () {
  ((CURRENT == 2)) &&
  _files -/ -W /mnt/c/Users/Mark/PhpstormProjects
}

Instead of this function, you may or may not prefer to add the directory to cdpath.

cdpath+=/mnt/c/Users/Mark/PhpstormProjects
1
  • FYI, it should be ((CURRENT == 2)) to complete only the first arg. I'm guessing 1 is the command itself.
    – mpen
    Commented Oct 3, 2019 at 5:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .