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

Re: [PATCH] _git: offer changed files relative to current directory



On Sat, Dec 05, 2009 at 03:42:58PM +0300, Alexey I. Froloff wrote:
> Just need pure-zsh "relative" implementation.
Here's my quick'n'dirty code:

relate()
{
    local -a what to res

    what=( ${(ps:/:)"${${${${1//\/\///}//\/.\///}%%/.}%%/}"} )
    to=( ${(ps:/:)"${${${${2//\/\///}//\/.\///}%%/.}%%/}"} )

    while (( $#what > 0 )) && (( $#to > 0 )) && [[ $what[1] == $to[1] ]]; do
	what[1]=()
	to[1]=()
    done

    while (( $#to > 0 )); do
	res+=..
	to[1]=()
    done

    res=( "$res[@]" "$what[@]" )

    echo ${(pj:/:)res}
}

relate Completion/Unix/Command/_git Functions/ 
../Completion/Unix/Command/_git

-- 
Regards,
Sir Raorn.

Attachment: signature.asc
Description: Digital signature



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