Skip to main content
edited body
Source Link
bxm
  • 5k
  • 1
  • 21
  • 24

I use Fish shell. Sometimes, I find myself in a child directory of a child directory of a child directory, several layers deep, and I want to return to the closest parent with a .git directory, as this directory represents the root project directory, so to speak.

For example, let's say I have this layout:

./
└── countries/
    ├── .git/
    └── regions/
        └── cities/

Whethere I am in countries/ or countries/regions/ or countries/regions/cities/, I would like this command to change directory to conutriescountries/, because it is the directory that contains .git.

How do I do this in Fish?

I use Fish shell. Sometimes, I find myself in a child directory of a child directory of a child directory, several layers deep, and I want to return to the closest parent with a .git directory, as this directory represents the root project directory, so to speak.

For example, let's say I have this layout:

./
└── countries/
    ├── .git/
    └── regions/
        └── cities/

Whethere I am in countries/ or countries/regions/ or countries/regions/cities/, I would like this command to change directory to conutries/, because it is the directory that contains .git.

How do I do this in Fish?

I use Fish shell. Sometimes, I find myself in a child directory of a child directory of a child directory, several layers deep, and I want to return to the closest parent with a .git directory, as this directory represents the root project directory, so to speak.

For example, let's say I have this layout:

./
└── countries/
    ├── .git/
    └── regions/
        └── cities/

Whethere I am in countries/ or countries/regions/ or countries/regions/cities/, I would like this command to change directory to countries/, because it is the directory that contains .git.

How do I do this in Fish?

Source Link
Flimm
  • 4.3k
  • 7
  • 30
  • 40

In Fish, how do I cd to the closest parent with a .git directory?

I use Fish shell. Sometimes, I find myself in a child directory of a child directory of a child directory, several layers deep, and I want to return to the closest parent with a .git directory, as this directory represents the root project directory, so to speak.

For example, let's say I have this layout:

./
└── countries/
    ├── .git/
    └── regions/
        └── cities/

Whethere I am in countries/ or countries/regions/ or countries/regions/cities/, I would like this command to change directory to conutries/, because it is the directory that contains .git.

How do I do this in Fish?