Search code examples
shellcdfish

Fish shell cd using relative path return: The directory “whatever” does not exist


I'm having trouble with a basic behavior of cd in fish shell.

cd to relative directory

I'm willing to change directory using a relative path without the ./. The directory exists:

❯ ls
addons/  custom-addons/  docker-compose.yml  

The directory is auto-completed, yet I can't change to it:

❯ cd addons/
cd: The directory “addons/” does not exist

CDPATH

set -gx CDPATH $CDPATH $HOME/projects

Solution

  • As described in the documentation section Special Variables:

    CDPATH, an array of directories in which to search for the new directory for the cd builtin. By default, the fish configuration defines CDPATH to be a universal variable with the values . and ~.

    Diagnostic

    I was overriding the default value while omitting . and ~ value.

    Solution

    Adding them back solved the issue, in ~/.config/fish/config.fish:

    set -gx CDPATH $CDPATH . ~ $HOME/projects
    

    Then reload fish with:

    exec fish