Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One of my favorites instead of aliasing ".."'s is this function:

  rationalise-dot() {
    if [[ $LBUFFER = *.. ]]; then
      LBUFFER+=/..
    else
      LBUFFER+=.
    fi
  }
  zle -N rationalise-dot
  bindkey . rationalise-dot
When you hit ... it will produce a slash and a ../ for each . you type after that.


Nice. But all you really need are:

  alias ..="cd .."
  alias ...="cd ../.."
After that, the more dots you type, the more error-prone it is, as you start to have to carefully count exactly how many directories you have to go up to get to where you want.

A better alternative is a script that shows a list of parent directories and lets you select them by typing the number or letter associated with them.

For example, if your current directory is "/a/b/c/d/e/f/g/h", then the script would display something like:

  List of parent directories:
  1 - a
  2 - b
  3 - c
  4 - d
  5 - e
  6 - f
  7 - g
  Please choose a directory: _
and you could type "3" to get to directory "c". That would be equivalent to typing "......", but much less error-prone and it'll save you the tedium of counting dots too.


Error prone isn't really that important in a shell when we're just talking about moving around. You type a bunch of dots which puts you in the region more or less -- plus I never really go from 8 directories deep to 2, (I doubt I even have an 8 directory deep section of my file tree) -- if I did I'd start from /, so it's more about 4 or 5 or so, in which case it's easy enough not to count but to know based on context. To each his own though.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: