about summary refs log tree commit diff
path: root/Completion/Unix/Type
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2016-01-18 02:36:59 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2016-01-20 07:49:29 +0000
commitc6fc6f80cd960af914400eb3f49c52fc17598ba5 (patch)
tree0b9b8338901dc0882d45d957dcddb321611bce73 /Completion/Unix/Type
parent9df6c728e8e43a20e337debbd17c6509f31f570f (diff)
downloadzsh-c6fc6f80cd960af914400eb3f49c52fc17598ba5.tar.gz
zsh-c6fc6f80cd960af914400eb3f49c52fc17598ba5.tar.xz
zsh-c6fc6f80cd960af914400eb3f49c52fc17598ba5.zip
37665: Completion: New helper _absolute_command_paths.
Diffstat (limited to 'Completion/Unix/Type')
-rw-r--r--Completion/Unix/Type/_absolute_command_paths29
1 files changed, 29 insertions, 0 deletions
diff --git a/Completion/Unix/Type/_absolute_command_paths b/Completion/Unix/Type/_absolute_command_paths
new file mode 100644
index 000000000..e9ab17023
--- /dev/null
+++ b/Completion/Unix/Type/_absolute_command_paths
@@ -0,0 +1,29 @@
+#autoload
+
+# This function completes 'ls' to '/bin/ls'
+_hashed_absolute_command_paths() {
+  local -aU set_of_dirs_of_hashed_commands=( ${^commands%/*}/ )
+  local i
+  integer ret=1
+  for i in $set_of_dirs_of_hashed_commands
+  do
+    compadd -M "l:|=$i" "$expl[@]" -a 'commands[(R)${~i}[^/]#]'
+    ret=0
+  done
+  return ret
+}
+
+# This function completes absolute pathnames of executables, e.g., /etc/rc.local
+_typed-in_absolute_command_paths() {
+  # TODO: the description "full path to an executable" and tag in the caller are ignored by _path_files
+  _path_files -/ -g '*(-*)' -P / -W /
+}
+
+_absolute_command_paths() {
+  _alternative \
+    'commands:hashed command by absolute path:_hashed_absolute_command_paths' \
+    'commands:full path to an executable:_typed-in_absolute_command_paths'
+}
+
+
+_absolute_command_paths "$@"