3 ms·
my version of .. function ..() { local temp_dir=$PWD cd .. for token in "$@"; do cd .. done OLDPWD=$temp_dir } so you can just t
by dw_arthur 3y ago
my version of ..
function ..() {
local temp_dir=$PWD
cd ..
for token in "$@"; do
cd ..
done
OLDPWD=$temp_dir
}
so you can just type .. to go up once or .. [word] to go up twice and so on
- JNRowe 3y agoThat seems potentially unpredictable versus building the string and calling cd once. For example, if you use direnv-type tools there may be side-effects along the route¹. zsh users could have state changing via the chpwd functions too, although that could be mitigated with "cd -q" at least. Obviously, it might not be an issue for your use, but just noting a potential gotcha if I were to lift it for example. [ Golf-y zsh, because vacation time and AoC has finished: ..() { cd ../${(pj:/:)${@/*/..}} } ] ¹ even just expensive setup/teardown delays would feel odd*