mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-01 19:41:00 +02:00
93 lines
2.4 KiB
Text
93 lines
2.4 KiB
Text
#autoload
|
|
|
|
local opts opt type=file glob group gopts dopts aopts tmp _file_pat_checked=yes
|
|
|
|
opts=()
|
|
group=()
|
|
gopts=()
|
|
dopts=(-/)
|
|
aopts=(-f)
|
|
while getopts "P:S:qr:R:W:F:J:V:X:f/g:M:12n" opt; do
|
|
case "$opt" in
|
|
/) type="${type}dir" ;;
|
|
g) type="${type}glob"; gopts=(-g "$OPTARG") ;;
|
|
[qn12]) opts=("$opts[@]" "-$opt" ) ;;
|
|
[JV]) group=( "-$opt" "$OPTARG") ;;
|
|
[^f]) opts=("$opts[@]" "-$opt" "$OPTARG") ;;
|
|
esac
|
|
done
|
|
|
|
if [[ "$group[2]" = files ]]; then
|
|
opts=("$opts[@]" "$group[@]")
|
|
group=()
|
|
fi
|
|
|
|
if zstyle -s ":completion${curcontext}:all-files" file-patterns tmp &&
|
|
[[ -n "$tmp" ]]; then
|
|
aopts=(-g "$tmp")
|
|
fi
|
|
if zstyle -s ":completion${curcontext}:directories" file-patterns tmp &&
|
|
[[ -n "$tmp" ]]; then
|
|
dopts=(-g "$tmp")
|
|
if [[ "$type" = (*dir*glob*|*glob*dir*) ]]; then
|
|
type=glob
|
|
elif [[ "$type" != *(dir|glob)* ]]; then
|
|
type="${type}dir"
|
|
fi
|
|
fi
|
|
if zstyle -s ":completion${curcontext}:globbed-files" file-patterns tmp &&
|
|
[[ -n "$tmp" ]]; then
|
|
gopts=(-g "$tmp")
|
|
if [[ "$type" != (*dir*glob*|*glob*dir*) ]]; then
|
|
if [[ "$type" = *(dir|glob)* ]]; then
|
|
type=glob
|
|
else
|
|
type=globall
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
case "$type" in
|
|
*dir*glob*|*glob*dir*) _tags globbed-files all-files ;;
|
|
*all*glob*|*glob*all*) _tags globbed-files all-files ;;
|
|
*glob*) _tags globbed-files directories all-files ;;
|
|
*dir*) _tags directories all-files ;;
|
|
*) _tags all-files ;;
|
|
esac
|
|
|
|
while _tags; do
|
|
if _requested all-files; then
|
|
if (( $#group )); then
|
|
group[2]=all-files
|
|
_setup all-files
|
|
fi
|
|
_path_files "$opts[@]" "$aopts[@]"
|
|
return
|
|
elif _requested directories; then
|
|
if _requested globbed-files; then
|
|
if (( $#group )); then
|
|
group[2]=globbed-files
|
|
_setup globbed-files
|
|
fi
|
|
_path_files "$opts[@]" "$dopts[@]" "$gopts[@]" && return 0
|
|
else
|
|
if (( $#group )); then
|
|
group[2]=directories
|
|
_setup directories
|
|
fi
|
|
_path_files "$opts[@]" "$dopts[@]" && return 0
|
|
fi
|
|
elif _requested globbed-files; then
|
|
if (( $#group )); then
|
|
group[2]=globbed-files
|
|
_setup globbed-files
|
|
fi
|
|
if [[ "$type" = (*dir*glob*|*glob*dir*) ]]; then
|
|
_path_files "$opts[@]" "$dopts[@]" "$gopts[@]" && return 0
|
|
else
|
|
_path_files "$opts[@]" "$gopts[@]" && return 0
|
|
fi
|
|
fi
|
|
done
|
|
|
|
return 1
|