1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-01 19:41:00 +02:00

users/15011: add path-completion style

This commit is contained in:
Peter Stephenson 2010-04-14 09:57:47 +00:00
parent c30b038a42
commit e694590b37
3 changed files with 39 additions and 8 deletions

View file

@ -1,3 +1,10 @@
2010-04-14 Peter Stephenson <pws@csr.com>
* users/15011: Completion/Unix/Type/_path_files,
Doc/Zsh/compsys.yo: add path-completion style to allow
completion of preceeding directories in files to be be turned
off.
2010-04-13 Peter Stephenson <pws@csr.com> 2010-04-13 Peter Stephenson <pws@csr.com>
* unposted: Functions/Calendar/calendar, Functions/Calendar/calendar_add, * unposted: Functions/Calendar/calendar, Functions/Calendar/calendar_add,
@ -13010,5 +13017,5 @@
***************************************************** *****************************************************
* This is used by the shell to define $ZSH_PATCHLEVEL * This is used by the shell to define $ZSH_PATCHLEVEL
* $Revision: 1.4953 $ * $Revision: 1.4954 $
***************************************************** *****************************************************

View file

@ -32,6 +32,7 @@ local tmp1 tmp2 tmp3 tmp4 i orig eorig pre suf tpre tsuf opre osuf cpre
local pats haspats ignore pfx pfxsfx sopt gopt opt sdirs ignpar cfopt listsfx local pats haspats ignore pfx pfxsfx sopt gopt opt sdirs ignpar cfopt listsfx
local nm=$compstate[nmatches] menu matcher mopts sort mid accex fake local nm=$compstate[nmatches] menu matcher mopts sort mid accex fake
local listfiles listopts tmpdisp origtmp1 Uopt local listfiles listopts tmpdisp origtmp1 Uopt
local accept_exact_dirs path_completion
integer npathcheck integer npathcheck
local -a Mopts local -a Mopts
@ -191,6 +192,11 @@ zstyle -a ":completion:${curcontext}:" fake-files fake
zstyle -s ":completion:${curcontext}:" ignore-parents ignpar zstyle -s ":completion:${curcontext}:" ignore-parents ignpar
zstyle -t ":completion:${curcontext}:paths" accept-exact-dirs &&
accept_exact_dirs=1
zstyle -T ":completion:${curcontext}:paths" path-completion &&
path_completion=1
if [[ -n "$compstate[pattern_match]" ]]; then if [[ -n "$compstate[pattern_match]" ]]; then
if { [[ -z "$SUFFIX" ]] && _have_glob_qual "$PREFIX" complete } || if { [[ -z "$SUFFIX" ]] && _have_glob_qual "$PREFIX" complete } ||
_have_glob_qual "$SUFFIX" complete; then _have_glob_qual "$SUFFIX" complete; then
@ -350,16 +356,17 @@ for prepath in "$prepaths[@]"; do
skipped= skipped=
cpre= cpre=
if zstyle -t ":completion:${curcontext}:paths" accept-exact-dirs && if [[ ( -n $accept_exact_dirs || -z $path_completion ) && \
[[ $pre = (#b)(*)/([^/]#) ]]; then $pre = (#b)(*)/([^/]#) ]]; then
# We've been told that we can accept an exact directory # We've been told either that we can accept an exact directory prefix
# prefix immediately. Try this with the longest path prefix # immediately, or that path expansion is inhibited. Try the longest
# first: this saves stats in the simple case and may get around # path prefix first: in the first case, this saves stats in the simple
# automount behaviour if early components don't yet exist. # case and may get around automount behaviour if early components don't
# yet exist, and in the second case this is the prefix we want to keep.
tmp1=$match[1] tmp1=$match[1]
tpre=$match[2] tpre=$match[2]
while true; do while true; do
if [[ -d $prepath$realpath$donepath$tmp1 ]]; then if [[ -z $path_completion || -d $prepath$realpath$donepath$tmp1 ]]; then
donepath=$donepath$tmp1/ donepath=$donepath$tmp1/
pre=$tpre pre=$tpre
break break

View file

@ -1123,6 +1123,9 @@ When this style is true, any prefix of a path that matches an existing
directory is accepted without any attempt to complete it further. directory is accepted without any attempt to complete it further.
Hence, in the given example, the path tt(/usr/bin/) is accepted Hence, in the given example, the path tt(/usr/bin/) is accepted
immediately and completion tried in that directory. immediately and completion tried in that directory.
If you wish to inhibit this behaviour entirely, set the tt(path-completion)
style (see below) to tt(false).
) )
kindex(add-space, completion style) kindex(add-space, completion style)
item(tt(add-space))( item(tt(add-space))(
@ -2259,6 +2262,20 @@ containing color names in the format of an X11 tt(rgb.txt) file. If
the style is not set but this file is found in one of various standard the style is not set but this file is found in one of various standard
locations it will be used as the default. locations it will be used as the default.
) )
item(tt(path-completion))(
This is used by filename completion. By default, filename completion
examines all components of a path to see if there are completions of
that component. For example, tt(/u/b/z) can be completed to
tt(/usr/bin/zsh). Explicitly setting this style to tt(false) inhibits this
behaviour for path components before the cursor; this overrides the
setting of tt(accept-exact-dirs).
Even with the style set to tt(false), it is still possible to complete
multiple paths by setting the option tt(COMPLETE_IN_WORD) and moving the
cursor back to the first component in the path to be completed. For
example, tt(/u/b/z) can be completed to tt(/usr/bin/zsh) if the cursor is
after the tt(/u).
)
kindex(pine-directory, completion style) kindex(pine-directory, completion style)
item(tt(pine-directory))( item(tt(pine-directory))(
If set, specifies the directory containing PINE mailbox files. There If set, specifies the directory containing PINE mailbox files. There