Reputation: 198228
I have a directory which contains several projects, and I want to run some commands against each project.
Now what I'm doing is:
cd /my/project/root
set root (pwd)
for p in *
cd $p
git reset --hard HEAD
git clean -dfx
cd $root
end
It works but not quite elegant. Is there any better way to let the part:
git reset --hard HEAD
git clean -dfx
runs in a temporary working dir, so I don't need to record the root
and cd $root
in the end of each loop?
Upvotes: 2
Views: 117
Reputation: 7459
Fish already maintains a history of recently visited directories so for your simple case just
for p in *
cd $p
do something
cd -
end
There is also the pushd and popd commands for more complex use cases.
Upvotes: 6