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

Re: [PATCH] expand '..n' to equivalent number of '..' segments in fixdir



Eric Cook wrote on Sun, 10 May 2020 03:09 -0400:
> On 5/10/20 3:06 AM, Eric Cook wrote:
> > I personally think a wrapper function is more appropriate.  
> 
> One not distributed with zsh itself that is.

Or a shell widget, like Mikael's rationalise-dot widget that lets one
type «cd ...» to get «cd ../..» and so on.  This also has the benefit
of not requiring completion functions to be taught about the new syntax.

I don't have his latest version handy, but I use a modified version:

_rationalise-dot2 ()
{
        if [[ $LBUFFER == *( ) ]]
        then
                zle .self-insert
		return
        fi
        local -a tokens; tokens=(${(z)LBUFFER}) 
        if [[ $tokens[-1] == (../|*/../) ]]
        then
                LBUFFER+=../ 
        elif [[ $tokens[-1] == '.' ]]
        then
                LBUFFER+=./ 
        else
                zle .self-insert
        fi
}
zle -N _rationalise-dot2
bindkey . _rationalise-dot2
bindkey -M isearch . self-insert

The zle calls inside the function don't pass argv through, but that
doesn't matter in practice.

Tweak to taste.



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