3

I'm using the following function to list the directory contents after changing the current working directory:

function c() {
  cd $@;
  ls;
}

How can i enable bash directory name completion for the 'c' function so that it also works for directories in $CDPATH?

| improve this question | | | | |
4

You can set the completion function of the command cd to the function c. First determine which completion function the cd command has assigned. In my case:

$ complete | grep " cd$"
complete -o nospace -F _cd cd

It's the function _cd, in my case _cd honours the $CDPATH variable. Now set your functions completion function:

$ complete -o nospace -F _cd c

Now, when typing c <tab><tab>, the same suggestions are made as when typing cd <tab><tab>

To make it permanent, write the command into your ~/.bashrc.

| improve this answer | | | | |

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.