* cdablevars and cd completion in 3.1.5 @ 1998-11-30 16:27 Andrej Borsenkow 1998-12-01 12:11 ` Bart Schaefer 0 siblings, 1 reply; 5+ messages in thread From: Andrej Borsenkow @ 1998-11-30 16:27 UTC (permalink / raw) To: ZSH users mailing list I have some long often visited directories; I named them with e.g. smbsrc and smbcvs, set cdablevars and can do 'cd smbsrc' quite O.K. Is it possible to also complete in smbsrc? That is, cd smbsrc/TAB -> list of subdirectories I am using pretty vanilla cdmatch function from some old ZSH distribution (but it is at least 3.0.x) thank you /andrej ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: cdablevars and cd completion in 3.1.5 1998-11-30 16:27 cdablevars and cd completion in 3.1.5 Andrej Borsenkow @ 1998-12-01 12:11 ` Bart Schaefer 1998-12-01 15:55 ` Sweth Chandramouli 0 siblings, 1 reply; 5+ messages in thread From: Bart Schaefer @ 1998-12-01 12:11 UTC (permalink / raw) To: Andrej Borsenkow, ZSH users mailing list As nobody else has responded to this yet ... On Nov 30, 7:27pm, Andrej Borsenkow wrote: } Subject: cdablevars and cd completion in 3.1.5 } } I have some long often visited directories; I named them with e.g. smbsrc } and smbcvs, set cdablevars and can do 'cd smbsrc' quite O.K. } } Is it possible to also complete in smbsrc? So the question is: Can one complete within a named directory? Which implies the question: Can one complete named directories? Let's start with the basic completion for diretories. In 3.0.5, that's compctl -g '*(-/)' cd pushd If you also want to complete directories that begin with a ".", you need compctl -g '*(-/)' + -g '*(-/D)' cd pushd In 3.1.5, almost the same effect is achieved more simply with compctl -/ cd pushd (the difference being that the 3.0.5 completion returns directories that begin with a "." anytime there are no other matching directories, whereas the -/ completion always requires that the "." be explicitly typed). From here on I'm going to use -/ in all examples, but unless I say otherwise they'll work in 3.0.5 too if you replace -/ with the -g patterns above. Now things begin to get complicated. There are three more things we may want to complete: 1. The names of cd-able variables. 2. Subdirectories of any directory named by a variable. 3. Subdirectories of the directories named in $cdpath. In 3.1.5 plus a recent patch from Sven W., (3) is as easy (Note 1) as compctl -/ -W "( . $cdpath )" cd pushd but in all earlier versions and for either of (1) and/or (2), a function such as cdmatch is required, so it might as well do all of this. First the compctl command: compctl -x 'S[/][~][./][../]' -/ \ - 'n[-1,/], s[]' -K cdmatch -S '/' -q \ -- cd pushd Remove that -q if you don't like autoremoveslash behavior. Now the function (cdpath part copied from the 3.1.5 dist, which is the same as the 3.0.5 dist): cdmatch () { local narg pref cdp cdv [[ -o cdablevars ]]; cdv=$? reply=() # This wipes cdablevars, hence remember it above emulate -R zsh setopt localoptions rcexpandparam read -nc narg read -Ac pref pref="${pref[$narg]%$2}" if ((cdv == 0)) then if [[ "$pref" != ([0-9]*|*/*) ]] then # Generate names of all variables whose values begin with '/'. # Don't include PWD or OLDPWD, lest they become named dirs! reply=( ${${${(M)$(set):#${pref:-[A-Za-z]}*${2:h}*\=/*}:#*(PWD|:)*}%\=/*} ) elif [[ "$pref" = */* ]] then # The head may be a variable whose value begins with '/'. # If you type PWD/ and then complete, PWD becomes named! eval '[[ "${'$pref:h'}" == /* ]]' && reply=( ~${pref}*$2(-/DN^M:t) ) fi fi # Finally, include anything along the cdpath that looks likely. cdp=(. $cdpath) reply=( $reply ${^cdp}/${pref}*$2(-/DN^M:t) ) } Now the obligatory bit of zsh arcana that still confuses me: zsh% echo ~/zshfun /home/schaefer/zshfun zsh% cd HE ^ With cursor here, this calls cdmatch and completes HOME/. But if instead I have zsh% cd HE/zshfun ^ With the cursor here, pressing tab does NOT call cdmatch! Why not? I have completeinword set. The word under the cursor contains a /, so it should match n[-1,/]. I expected it to call cdmatch with 1=H 2=E/zshfun and to be able to read HE/zshfun into $pref. If Instead I have zsh% cd HOME/zn ^ with the cursor here, I can complete to HOME/zshfun. I have the feeling this is something I once knew, but maybe it needs to be written down somewhere. Whew. Note 1: To handle directories in cdpath that have spaces in their names, use compctl -/ -W "( . ${(@j( ))cdpath:gs/ /\\\\\\ /} )" cd pushd -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: cdablevars and cd completion in 3.1.5 1998-12-01 12:11 ` Bart Schaefer @ 1998-12-01 15:55 ` Sweth Chandramouli 1998-12-01 18:24 ` Bart Schaefer 1998-12-01 19:02 ` Andrej Borsenkow 0 siblings, 2 replies; 5+ messages in thread From: Sweth Chandramouli @ 1998-12-01 15:55 UTC (permalink / raw) To: ZSH users mailing list On Tue, Dec 01, 1998 at 04:11:39AM -0800, Bart Schaefer wrote: > So the question is: Can one complete within a named directory? > > Which implies the question: Can one complete named directories? > > Let's start with the basic completion for diretories. In 3.0.5, that's > > compctl -g '*(-/)' cd pushd > > If you also want to complete directories that begin with a ".", you need > > compctl -g '*(-/)' + -g '*(-/D)' cd pushd > > In 3.1.5, almost the same effect is achieved more simply with > > compctl -/ cd pushd > > (the difference being that the 3.0.5 completion returns directories that > begin with a "." anytime there are no other matching directories, whereas > the -/ completion always requires that the "." be explicitly typed). From > here on I'm going to use -/ in all examples, but unless I say otherwise > they'll work in 3.0.5 too if you replace -/ with the -g patterns above. i'm running 3.1.4, with "compctl -g '*(-/)' cd pushd", and i get tab completion on all matching directories, including ones with dot-prefixes, even if not explicitly typed... i just checked, and i get the same behaviour with just "compctl -/ cd pushd". the manpage for zshcompctl describes the -/ flag as completing "Just filesystem paths"; what about that would imply that dot-prefixes should not be included? is the behaviour you describe a change in 3.1.5? > Now the obligatory bit of zsh arcana that still confuses me: > > zsh% echo ~/zshfun > /home/schaefer/zshfun > zsh% cd HE > ^ > With cursor here, this calls cdmatch and completes HOME/. > But if instead I have > zsh% cd HE/zshfun > ^ > With the cursor here, pressing tab does NOT call cdmatch! > Why not? I have completeinword set. The word under the > cursor contains a /, so it should match n[-1,/]. I expected > it to call cdmatch with 1=H 2=E/zshfun and to be able to > read HE/zshfun into $pref. If Instead I have > zsh% cd HOME/zn > ^ > with the cursor here, I can complete to HOME/zshfun. at first, i assumed you meant $HOME and not just HOME. some further checking, however, shows that zsh seems to do a check of environment variables if you try to cd to a directory that is not in your path and not a named directory, and if it finds a matching env. var., it implicitly names the corresponding directory: (astaroth)~: cd ~ adm chuck listen noaccess oracle7 sirk sys arch daemon lp nobody perl smtp throck bench jasonbb mddeath nobody4 root src truyen bin/ leif netscape nuucp roth sweth (astaroth)~: cd FPATH ~FPATH (astaroth)~: cd ~ FPATH bin/ leif netscape nuucp roth sweth adm chuck listen noaccess oracle7 sirk sys arch daemon lp nobody perl smtp throck bench jasonbb mddeath nobody4 root src truyen my tab-completion doesn't work at all against named directories unless i've explicitly prefixed them with a ~ (e.g. "cd ~sw<TAB>" to get "cd sweth", vs. "cd sw<TAB>", which does nothing), and i don't have time right now to dig into your (impressive and very tempting) completion, but my best guess would be that it has something to do with the way that that implicit naming takes place. do you get the same behaviour when trying zsh% cd ~HE/zshfun ^cursor here when tabbing -- sweth. -- Sweth Chandramouli IS Coordinator, The George Washington University <sweth@gwu.edu> / (202) 994 - 8521 (V) / (202) 994 - 0458 (F) <a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a> ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: cdablevars and cd completion in 3.1.5 1998-12-01 15:55 ` Sweth Chandramouli @ 1998-12-01 18:24 ` Bart Schaefer 1998-12-01 19:02 ` Andrej Borsenkow 1 sibling, 0 replies; 5+ messages in thread From: Bart Schaefer @ 1998-12-01 18:24 UTC (permalink / raw) To: Sweth Chandramouli, ZSH users mailing list On Dec 1, 10:55am, Sweth Chandramouli wrote: } Subject: Re: cdablevars and cd completion in 3.1.5 } } > (the difference being that the 3.0.5 completion returns directories that } > begin with a "." anytime there are no other matching directories, whereas } > the -/ completion always requires that the "." be explicitly typed). } } i'm running 3.1.4, with "compctl -g '*(-/)' cd pushd", and i } get tab completion on all matching directories, including ones with } dot-prefixes, even if not explicitly typed... i just checked, and i } get the same behaviour with just "compctl -/ cd pushd". It sounds like you have the globdots option set. } the manpage } for zshcompctl describes the -/ flag as completing "Just filesystem } paths"; what about that would imply that dot-prefixes should not be } included? Nothing except that dot-prefixed files are traditionally hidden from globbing and ls and so forth, so -/ continues the trend. } is the behaviour you describe a change in 3.1.5? It's not a behavior change. } > zsh% cd HE } > ^ } > With cursor here, this calls cdmatch and completes HOME/. } > zsh% cd HOME/zn } > ^ } > with the cursor here, I can complete to HOME/zshfun. } } at first, i assumed you meant $HOME and not just HOME. some } further checking, however, shows that zsh seems to do a check of } environment variables if you try to cd to a directory that is not in } your path and not a named directory, and if it finds a matching env. } var., it implicitly names the corresponding directory: Any variable whose value begins with a / character, not just environment variables; but only if you have the cdablevars option set, which it seems you do. } my tab-completion doesn't work at all against named directories } unless i've explicitly prefixed them with a ~ (e.g. "cd ~sw<TAB>" to } get "cd sweth", vs. "cd sw<TAB>", which does nothing) That's correct; the whole point of my posting was to cause completion to work even without the leading tilde, just for people who want to use cdablevars. I admit it's probably not all that widely useful. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com ^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: cdablevars and cd completion in 3.1.5 1998-12-01 15:55 ` Sweth Chandramouli 1998-12-01 18:24 ` Bart Schaefer @ 1998-12-01 19:02 ` Andrej Borsenkow 1 sibling, 0 replies; 5+ messages in thread From: Andrej Borsenkow @ 1998-12-01 19:02 UTC (permalink / raw) To: ZSH users mailing list > -----Original Message----- > From: Sweth Chandramouli [mailto:sweth@astaroth.nit.gwu.edu] > Sent: Tuesday, December 01, 1998 6:55 PM > To: ZSH users mailing list > Subject: Re: cdablevars and cd completion in 3.1.5 > > > On Tue, Dec 01, 1998 at 04:11:39AM -0800, Bart Schaefer wrote: > > So the question is: Can one complete within a named directory? I am really sorry, but looks, like the message of Bart never hit me (looks, like we got some problems with mail today). May I ask to resend it to me, please? thank you /andrej ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1998-12-01 19:04 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1998-11-30 16:27 cdablevars and cd completion in 3.1.5 Andrej Borsenkow 1998-12-01 12:11 ` Bart Schaefer 1998-12-01 15:55 ` Sweth Chandramouli 1998-12-01 18:24 ` Bart Schaefer 1998-12-01 19:02 ` Andrej Borsenkow
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).