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

Re: How to complete commands on a different/generated PATH ?



On Aug 28,  5:22pm, C. v. Stuckrad wrote:
} Subject: How to complete commands on a different/generated PATH ?
}
} We use a set of macros 'x11x' 'ow3x' '...some_other_s', which
} manipulate the environment to start a program in the 'correct world'.
} 
} BUT HOW TO  'first change the PATH, then glob on the new PATH' ?

The best way to do this depends on what you mean by "macro".  If it's
nothing more than a zsh alias that expands to a PATH=... assignment,
there might be some tricks to play.  However:

----------

function Xcomplete {
    emulate -R zsh
    setopt localoptions
    local nword args
    read -nc nword
    read -Ac args
    reply=($(
	case $args[0] in
	(x11x) PATH=the:path:used:by:x11x ;;	# Change these suitably for
	(ow3x) PATH=the:path:used:by:ow3x ;;	# each of your macros' PATH
	esac
	rehash
	whence -pm ${args[$nword]:t}\*
    ))
    reply=(${reply##*/})
}
compctl -x 'p[1]' -K Xcomplete - 'p[2,-1]' -l '' -- x11x ow3x

----------

Note the use of the new "case" syntax.  There is STILL a bug in parsing
of "case" statements inside $( ... ) which causes the old-style "case"
to fail.  Vis:

zsh% echo $(
cmdsubst> case foo in
cmdsubst> foo)
zsh: parse error near `foo'
zsh: parse error in command substitution

The close-paren in the "case" pattern ends the $( ... ) parse.

Of course, this doesn't work in bash either, and is probably the
reason that POSIX created the new case syntax ....

Oh, there is one small nit about the above function:  Because of the
way "whence" works, it returns x11x, ow3x, and Xcomplete as possible
completions.  So you can end up with:

zsh% x11x x11x ow3x ...

and it'll still be happily completing away.  You can use extend it to
strip those out if you want.

-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"



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