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

Re: Stopping completion from using $cdpath



> Is there a way to stop zsh from using $cdpath when doing completion ? If I
> have a directory with only one sub-directory and I do
> 
> cd <TAB>
> 
> it tries to complete from $cdpath instead of directly going into the
> sub-directory. If I unset cdpath, it works fine...

I use this function to allow completion from cdpath of all files (or at
least those files that are following the default completion), so for
example

alpha11-~/private% echo $cdpath
./ /u/pol1b/oma1000/
alpha11-~/private% cd<tab>
cv/       eric/     igor/     letters/  rm/
alpha11-~/private% ls -d ~/*(/)
/u/pol1b/oma1000/LaTeX/         /u/pol1b/oma1000/mail/
/u/pol1b/oma1000/Mail/          /u/pol1b/oma1000/misc/
/u/pol1b/oma1000/News/          /u/pol1b/oma1000/nsmail/
/u/pol1b/oma1000/apps/          /u/pol1b/oma1000/pc/
/u/pol1b/oma1000/carol/         /u/pol1b/oma1000/private/
/u/pol1b/oma1000/cerius/        /u/pol1b/oma1000/public_html/
/u/pol1b/oma1000/data/          /u/pol1b/oma1000/teaching/
/u/pol1b/oma1000/diagrams/      /u/pol1b/oma1000/tensile/
/u/pol1b/oma1000/instructions/  /u/pol1b/oma1000/theory/
/u/pol1b/oma1000/local/         /u/pol1b/oma1000/unit-cells/
alpha11-~/private% cd m<tab>  [the m then gets changed to ~/m]
~/mail/  ~/misc/

Hope this makes sense!

Owen

# zsh function
# compctl-cdpath

# Completion for general globbing, completing for stuff in cdpath,
# uses directories listed in cdpath, and replaces ... with ../.. .

# Usage:
# compctl -D -f + -QU -S '' -K compctl-cdpath

######################################################################
local pref="${1:fs|...|../..|}"
integer i

setopt localoptions
setopt nullglob rcexpandparam
unsetopt rcexpandparam markdirs equals

reply=()

######################################################################
# Anything starting with `~' or `=' isn't handled by compctl-cdpath.
[[ $pref[1] == [\~\=] ]] && return

# Check if the completion exists in the current directory.
reply=(${pref}*)

# If the completion doesn't exist in the current directory, use cdpath.
[[ -z $reply ]] && reply=("${(@)reply}" ${^cdpath%/}/${pref}*)

# If there were no completions, return $pref (allowing ... -> ../..)
[[ -z $reply ]] && reply=("$pref")

# Replace reply with a nicer version.
unset pref origpref
reply=($(print -D "${(@)reply}"))

######################################################################
# Add / to all directories, spaces to files.
i=1
while (( i <= ${(w)#reply} )); do
  [[ -d ${~reply[i]}/ ]] && reply[i]="${reply[i]%/}/"
  [[ -f ${~reply[i]} ]] && reply[i]="$reply[i] "
  ((i++))
done




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