You should instead
pushd /my/path && command && popd
Both in bash AND in fish!
Re:Fish Shell 3.5.0
by CJefferson on Friday June 17, 2022 @02:31AM
(#31774752)
the problem with that is I ended up in the wrong directory if I press ctrl+c, or in the exact examples you give, if command fails.
If it's just make you're doing that for "make -C mydir" does that and puts you back in the original directory when it's done.
Re:Fish Shell 3.5.0
by tomjakubowski on Thursday June 16, 2022 @02:21PM
(#31769256)
I do this too (in zsh), but maybe writing a function callable like this would work:
with mydir make
Although you'd want to be able to write things like with mydir make && ./bin/myprog
and parse everything to the right of `mydir' as a shell pipeline. That might be the sticking point in fish.I use this a lot in my scripts - handy when you want to capture the output or execute a command in a different directory.
Fish doesn't have anything like that, there are a few workaround, but none of them are (in my opinion) anywhere near as nice.