Freewind
Freewind

Reputation: 198228

How to set temporary for some script in fish?

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

Answers (1)

Kurtis Rader
Kurtis Rader

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

Related Questions