Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Neat hash -d trick



[Aside to -workers:  This reminds me about Mikael Magnusson's thread
for his proposed HASH_LOOKUP option, which sort of died out without
resolution after a discussion of findcmd() behaving oddly.]

On Oct 22, 12:34am, Nikolai Weibull wrote:
}
} for ((i = 1; i < 9; i++)); do

You probably mean <= 9 there?  Or just

  for i in {1..9}

}   hash -d .$i=${(j:/:)${(l:2::.:)${(s::)${(l:i::.:)}}}}

    hash -d .$i=${${(l:i*3::../:)}%/}

} done
} 
} cd ~.4/dir

A generic word of caution about using "hash -d": if you for any reason
change the value of $PATH or $path after this, all your custom hash
entries are lost when the table is rebuilt for the new searchpath.

A similar trick:

    dotdot() {
      if (( NUMERIC > 0 ))
      then LBUFFER+=..; repeat $((NUMERIC-1)) LBUFFER+=/..
      else LBUFFER+=.
      fi
    }
    zle -N dotdot
    bindkey . dotdot

Now you can type ESC 4 . to insert ../../../.. (or ESC 9 ESC 9 . to
insert 99 levels, if for some insane reason you need that many).

} What would be even sweeter is if someone would come up with a way to
} do this with only one call to hash -d without writing out all the
} expansions

Because the counter has to be referenced twice in the expansion, I
don't think there's any way of avoiding the "for" loop that's worth
the effort to figure out.  However,

    for i in {1..9}; h+=(.$i=${${(l:i*3::../:)}%/}); hash -d $h

Or to avoid leaving $i and $h with a value at the end,

    hash -d $( for i in {1..9}; print .$i=${${(l:i*3::../:)}%/} )



Messages sorted by: Reverse Date, Date, Thread, Author