From 027604400ba98f4c947784fc691dc7c93b9bf366 Mon Sep 17 00:00:00 2001 From: Sven Wischnowsky Date: Wed, 11 Jul 2001 08:22:02 +0000 Subject: 15352,15357 --- Completion/Base/Completer/_prefix | 59 +++++++++++++++++++++++++++++++++++++ Completion/Unix/Command/_man | 61 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 Completion/Base/Completer/_prefix create mode 100644 Completion/Unix/Command/_man (limited to 'Completion') diff --git a/Completion/Base/Completer/_prefix b/Completion/Base/Completer/_prefix new file mode 100644 index 000000000..3ec153245 --- /dev/null +++ b/Completion/Base/Completer/_prefix @@ -0,0 +1,59 @@ +#autoload + +# Try to ignore the suffix. A bit like e-o-c-prefix. + +[[ _matcher_num -gt 1 || -z "$SUFFIX" ]] && return 1 + +local comp curcontext="$curcontext" tmp suf="$SUFFIX" \ + _completer _completer_num \ + _matcher _c_matcher _matchers _matcher_num + +zstyle -a ":completion:${curcontext}:" completer comp || + comp=( "${(@)_completers[1,_completer_num-1][(R)_prefix(|:*),-1]}" ) + +if zstyle -t ":completion:${curcontext}:" add-space; then + ISUFFIX=" $SUFFIX" +else + ISUFFIX="$SUFFIX" +fi +SUFFIX='' + +_completer_num=1 + +for tmp in "$comp[@]"; do + if [[ "$tmp" = *:-* ]]; then + _completer="${${tmp%:*}[2,-1]//_/-}${tmp#*:}" + tmp="${tmp%:*}" + elif [[ $tmp = *:* ]]; then + _completer="${tmp#*:}" + tmp="${tmp%:*}" + else + _completer="${tmp[2,-1]//_/-}" + fi + curcontext="${curcontext/:[^:]#:/:${_completer}:}" + + zstyle -a ":completion:${curcontext}:" matcher-list _matchers || + _matchers=( '' ) + + _matcher_num=1 + _matcher='' + for _c_matcher in "$_matchers[@]"; do + if [[ "$_c_matcher" == +* ]]; then + _matcher="$_matcher $_c_matcher[2,-1]" + else + _matcher="$_c_matcher" + fi + + if [[ "$tmp" != _prefix ]] && "$tmp"; then + [[ compstate[nmatches] -gt 1 ]] && return 0 + compadd -U -i "$IPREFIX" -I "$ISUFFIX" - "${compstate[unambiguous]%$suf}x" + compstate[list]= + compstate[insert]=unambiguous + return 0 + fi + (( _matcher_num++ )) + done + (( _completer_num++ )) +done + +return 1 diff --git a/Completion/Unix/Command/_man b/Completion/Unix/Command/_man new file mode 100644 index 000000000..0bdd8db8b --- /dev/null +++ b/Completion/Unix/Command/_man @@ -0,0 +1,61 @@ +#compdef man apropos whatis + +_man() { + local dirs expl mrd awk + + if [[ $service == man ]] && (( $words[(I)-l] + $words[(I)--local-file] )); then + _files || return 0 + fi + + if (( ! $#manpath )); then + local mp + mp=($(manpath 2>/dev/null)) + [[ "$mp" == *:* ]] && mp=( ${(s.:.)mp} ) + manpath=( $mp ) + fi + + (( $#manpath )) || manpath=( ${(s.:.)$(manpath 2>/dev/null)} ) || + manpath=( /usr/man(-/) /(opt|usr)/(dt|share|X11R6|local)/(cat|)man(-/) ) + + # `sman' is the SGML manual directory for Solaris 7. + # 1M is system administrator commands on SVR4 + + mrd=(${^manpath/\%L/${LANG:-En_US.ASCII}}/mandb(N)) + + if [[ $words[2] = (<->*|1M|l|n) ]]; then + dirs=( $^manpath/(sman|man|cat)${words[2]}/ ) + awk="\$2 == \"$words[2]\" {print \$1}" + else + dirs=( $^manpath/(sman|man|cat)*/ ) + awk='{print $1}' + fi + + _wanted manuals expl 'manual page' _man_pages +} + +_man_pages() { + local matcher pages dummy + + zparseopts -E M+:=matcher + + if (( $#matcher )); then + matcher=( ${matcher:#-M} ) + matcher="$matcher" + else + matcher= + fi + + pages=( $dirs ) + compfiles -p pages '' '' "$matcher" '' dummy '*' + pages=( ${^~pages}(N:t:r) ) + + (($#mrd)) && pages[$#pages+1]=($(awk $awk $mrd)) + + # Remove any compression suffix, then remove the minimum possible string + # beginning with .<->: that handles problem cases like files called + # `POSIX.1.5'. + + compadd "$@" - ${pages%.(?|<->*)} +} + +_man "$@" -- cgit 1.4.1