Hacker News new | ask | show | jobs
by dw_arthur 913 days 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
1 comments

That 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*