about summary refs log tree commit diff
path: root/Completion/Unix/Type
diff options
context:
space:
mode:
authorPaul Ackersviller <packersv@users.sourceforge.net>2007-12-03 02:31:49 +0000
committerPaul Ackersviller <packersv@users.sourceforge.net>2007-12-03 02:31:49 +0000
commitb32f902ba598c851196b037178233477c2411876 (patch)
treeb7cbfbe7ef82be75804f4a1c1800506208b7d489 /Completion/Unix/Type
parent79a0a88e660f0b4027a75d374efb7ffba3011adc (diff)
downloadzsh-b32f902ba598c851196b037178233477c2411876.tar.gz
zsh-b32f902ba598c851196b037178233477c2411876.tar.xz
zsh-b32f902ba598c851196b037178233477c2411876.zip
Bring various .distfiles up to date and merge any extra completions onto 4.2 branch.
Diffstat (limited to 'Completion/Unix/Type')
-rw-r--r--Completion/Unix/Type/.distfiles58
-rw-r--r--Completion/Unix/Type/_list_files69
-rw-r--r--Completion/Unix/Type/_path_commands77
3 files changed, 193 insertions, 11 deletions
diff --git a/Completion/Unix/Type/.distfiles b/Completion/Unix/Type/.distfiles
index 2803318d5..4801f84c1 100644
--- a/Completion/Unix/Type/.distfiles
+++ b/Completion/Unix/Type/.distfiles
@@ -1,15 +1,51 @@
 DISTFILES_SRC='
 .distfiles
-_arch_archives       _arch_namespace
-_dict_words          _mailboxes           _perl_modules        _tex
-_diff_options        _my_accounts         _pids                _texi
-_dir_list            _newsgroups          _ports               _tilde_files
-_directories         _other_accounts      _printers            _urls
-_domains             _path_files          _ps                  _user_at_host
-_files               _pdf                 _pspdf               _users
-_groups              _perl_basepods       _signals             _users_on
-_hosts               _tar_archive         _time_zone
-_file_systems        _net_interfaces      _terminals           _locales
-_java_class          _services		  _email_addresses     _global_tags
+_arch_archives
+_arch_namespace
+_bind_addresses
+_canonical_paths
+_ctags_tags
+_dict_words
+_diff_options
+_dir_list
+_directories
+_domains
+_email_addresses
+_file_systems
+_files
+_global_tags
+_groups
+_hosts
+_java_class
+_ld_debug
+_list_files
+_locales
+_mailboxes
 _mime_types
+_my_accounts
+_net_interfaces
+_newsgroups
+_other_accounts
+_path_commands
+_path_files
+_pdf
+_perl_basepods
+_perl_modules
+_pids
+_ports
+_printers
+_ps
+_pspdf
+_services
+_signals
+_tar_archive
+_terminals
+_tex
+_texi
+_tilde_files
+_time_zone
+_urls
+_user_at_host
+_users
+_users_on
 '
diff --git a/Completion/Unix/Type/_list_files b/Completion/Unix/Type/_list_files
new file mode 100644
index 000000000..5e745d9d1
--- /dev/null
+++ b/Completion/Unix/Type/_list_files
@@ -0,0 +1,69 @@
+#autoload
+
+# Helper function for _path_files to handle the file-list style.
+
+# arguments:
+#  name of parameter containing file matches
+#  directory prefix
+# Sets array listfiles to the display strings and the array
+# listopts appropriately to be added to the compadd command line.
+
+local stat f elt what dir
+local -a stylevals
+integer ok
+
+listfiles=()
+listopts=()
+
+zstyle -a ":completion:${curcontext}:" file-list stylevals || return 1
+
+# TODO: more flexible way of handling the following?  e.g. use $compstate?
+case $WIDGETSTYLE in
+  (*complete*)
+  what=insert
+  ;;
+
+  (*)
+  what=list
+  ;;
+esac
+
+for elt in $stylevals; do
+  case $elt in
+    (*($what|all|true|1|yes)*=<->)
+    # use long format if no more than the given number of matches
+    (( ${(P)#1} <= ${elt##*=} )) && (( ok = 1 ))
+    break
+    ;;
+
+    (*($what|all|true|1|yes)[^=]#)
+    # always use long format
+    (( ok = 1 ))
+    break
+    ;;
+  esac
+done
+
+(( ok )) || return 1
+
+zmodload -i zsh/stat 2>/dev/null || return 1
+
+dir=${2:+$2/}
+dir=${(Q)dir}
+
+for f in ${(PQ)1}; do
+  if [[ ! -e "$dir$f" ]]; then
+    listfiles+=("$dir$f")
+    continue
+  fi
+
+  # Borrowed from Functions/Example/zls
+  stat -s -H stat -F "%b %e %H:%M" - "$dir$f" >/dev/null 2>&1
+
+  listfiles+=("$stat[mode] ${(l:3:)stat[nlink]} ${(r:8:)stat[uid]} \
+ ${(r:8:)stat[gid]} ${(l:8:)stat[size]} $stat[mtime] $f")
+done
+
+(( ${#listfiles} )) && listopts=(-d listfiles -l -o)
+
+return 0
diff --git a/Completion/Unix/Type/_path_commands b/Completion/Unix/Type/_path_commands
new file mode 100644
index 000000000..714e2e232
--- /dev/null
+++ b/Completion/Unix/Type/_path_commands
@@ -0,0 +1,77 @@
+#autoload
+
+(( $+functions[_path_commands_caching_policy] )) ||
+_path_commands_caching_policy() {
+
+local oldp file
+typeset -a dbfiles
+
+# rebuild if cache is more than a week old
+oldp=( "$1"(Nmw+1) )
+(( $#oldp )) && return 0
+
+dbfiles=(/usr/share/man/index.(bt|db|dir|pag)(N) \
+  /usr/man/index.(bt|db|dir|pag)(N) \
+  /var/cache/man/index.(bt|db|dir|pag)(N) \
+  /var/catman/index.(bt|db|dir|pag)(N) \
+  /usr/share/man/*/whatis(N))
+
+for file in $dbfiles; do
+  [[ $file -nt $1 ]] && return 0
+done
+
+return 1
+}
+
+_path_commands() {
+local need_desc expl ret=1
+
+if zstyle -T ":completion:${curcontext}:" verbose; then
+  local update_policy first
+  if [[ $+_command_descriptions -eq 0 ]]; then
+    first=yes
+    typeset -A -g _command_descriptions
+  fi
+  zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+  [[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" \
+    cache-policy _path_commands_caching_policy
+  if ( [[ -n $first ]] || _cache_invalid command-descriptions ) && \
+    ! _retrieve_cache command-descriptions; then
+    local line
+    for line in "${(f)$(_call_program command-descriptions whatis -s 1 -r .\\\*\; whatis -s 6 -r .\\\* 2> /dev/null)}"; do
+      [[ -n ${line:#(#b)([^ ]#) #\([^ ]#\)( #\[[^ ]#\]|)[ -]#(*)} ]] && continue;
+      [[ -z $match[1] || -z $match[3] || -z ${${match[1]}:#*:*} ]] && continue;
+      _command_descriptions[$match[1]]=$match[3]
+    done
+    _store_cache command-descriptions _command_descriptions
+  fi
+
+  (( $#_command_descriptions )) && need_desc=yes
+fi
+
+if [[ -n $need_desc ]]; then
+  typeset -a dcmds descs cmds
+  local desc cmd sep
+  for cmd in ${(@)commands[(I)$PREFIX*]}; do
+    desc=$_command_descriptions[$cmd]
+    if [[ -z $desc ]]; then
+      cmds+=$cmd
+    else
+      dcmds+=$cmd
+      descs+="$cmd:$desc"
+    fi
+  done
+  zstyle -s ":completion:${curcontext}:" list-separator sep || sep=--
+  zformat -a descs " $sep " $descs
+  descs=("${(@r:COLUMNS-1:)descs}")
+  _wanted commands expl 'external command' \
+    compadd "$@" -ld descs -a dcmds && ret=0
+  _wanted commands expl 'external command' compadd "$@" -a cmds && ret=0
+else
+  _wanted commands expl 'external command' compadd "$@" -k commands && ret=0
+fi
+
+return $ret
+}
+
+_path_commands "$@"