1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-12-29 19:12:20 +01:00

change file completion default to offer globbed files and directories on first try (15995)

This commit is contained in:
Sven Wischnowsky 2001-10-09 12:56:02 +00:00
parent 2a2de0abea
commit 933813e971
3 changed files with 47 additions and 19 deletions

View file

@ -1,3 +1,9 @@
2001-10-09 Sven Wischnowsky <wischnow@zsh.org>
* 15995: Completion/Unix/Type/_files, Doc/Zsh/compsys.yo:
change file completion default to offer globbed files and
directories on first try
2001-10-09 Peter Stephenson <pws@csr.com>
* 15994: Completion/compinstall: handle list-suffixes; make

View file

@ -37,12 +37,25 @@ if zstyle -a ":completion:${curcontext}:" file-patterns tmp; then
done
else
if [[ "$type" = *g* ]]; then
if [[ "$type" = */* ]]; then
pats=( " ${glob//:/\\:}:globbed-files *(-/):directories" '*:all-files ' )
else
pats=( " ${glob//:/\\:}:globbed-files "
'*(-/):directories ' '*:all-files ' )
fi
# People prefer to have directories shown on first try as default.
# Even if the calling function didn't use -/.
#
# if [[ "$type" = */* ]]; then
pats=( " ${glob//:/\\:}:globbed-files *(-/):directories" '*:all-files '
### We could allow _next_tags to offer only globbed-files or directories
### by adding:
### " ${glob//:/\\:}:only-globbed-files " ' *(-/):only-directories '
)
# else
# pats=( " ${glob//:/\\:}:globbed-files "
# '*(-/):directories ' '*:all-files ' )
# fi
elif [[ "$type" = */* ]]; then
pats=( '*(-/):directories ' '*:all-files ' )
else
@ -53,15 +66,16 @@ fi
tried=()
for def in "$pats[@]"; do
eval "def=( ${${def:gs/\\:/\\\\\\\\\\\\:}//(#b)([][()|*?^#~<>])/\\${match[1]}} )"
tmp="${(@M)def#*[^\\]:}"
(( $tried[(I)${(q)tmp}] )) && continue
tried=( "$tried[@]" "$tmp" )
for sdef in "$def[@]"; do
tag="${${sdef#*[^\\]:}%%:*}"
pat="${${sdef%%:${tag}*}//\\:/:}"
(( $tried[(I)${(q)pat}] )) && continue
tried=( "$tried[@]" "$pat" )
if [[ "$sdef" = *:${tag}:* ]]; then
descr="${(Q)sdef#*:${tag}:}"
else
@ -86,7 +100,13 @@ for def in "$pats[@]"; do
done
(( ret )) || break
done
### For that _next_tags change mentioned above we would have to
### comment out the following line. (Or not, depending on the order
### of the patterns.)
[[ "$pat" = '*' ]] && return ret
done
(( ret )) || return 0
done

View file

@ -1111,10 +1111,12 @@ kindex(file-patterns, completion style)
item(tt(file-patterns))(
In most places where filenames are completed, the function tt(_files)
is used which can be configured with this style. If the style is
unset, tt(_files) offers, one after another, up to three tags:
unset, tt(_files) offers, up to three tags:
`tt(globbed-files)',
`tt(directories)' and `tt(all-files)', depending on the types of files
expected by the caller of tt(_files).
expected by the caller of tt(_files). The first two
(`tt(globbed-files)' and `tt(directories)') are normally offered
together to make it easier to complete files in sub-directories.
If the tt(file-patterns) style is set, the default tags are not
used. Instead, the value of the style says which tags and which
@ -1149,15 +1151,15 @@ the string on the line, one would do:
example(zstyle ':completion:*:*:rm:*' file-patterns \
'*.o:object-files' '%p:all-files')
Another interesting example is to change the default behaviour that
makes completion first offer files matching the patterns given by the
calling function, then directories and then all files. Many people
prefer to get both the files matching the given patterns and the
directories in the first try and all files at the second try. To
achieve this, one could do:
Another interesting example is to change the default behaviour in a
way that makes completion first offer files matching the patterns
given by the calling function, then directories and then all files.
Some people prefer this over getting both the files matching the given
patterns and the directories in the first try and all files at the
second try. To achieve this, one could do:
example(zstyle ':completion:*' file-patterns \
'%p:globbed-files *(-/):directories' '*:all-files')
'%p:globbed-files' '*(-/):directories' '*:all-files')
This works even for contexts in which all files would be completed,
because tt(_files) will not try a pattern more than once and it stops