4 ms·
Personally, I'm a lover of subshells, I often write things like (cd mydir && make), making use of the fact the 'cd mydir' only happens in the subshell. Fish do
by CJefferson 4y ago
Personally, I'm a lover of subshells, I often write things like (cd mydir && make), making use of the fact the 'cd mydir' only happens in the subshell.
Fish doesn't have anything like that, there are a few workaround, but none of them are (in my opinion) anywhere near as nice.
- 8ytecoder 4y agoI use this a lot in my scripts - handy when you want to capture the output or execute a command in a different directory.
- lytedev 4y agoset output (echo captured) echo $output > captured And if you wanna run a command in another dir: pushd other_dir run_command popd
- onei 4y agoIf 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.
- tomjakubowski 4y agoI 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.
- lytedev 4y agoYou should instead pushd /my/path && command && popd Both in bash AND in fish!
- CJefferson 4y agothe 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.