about summary refs log tree commit diff
path: root/Functions/Misc/cdmatch2
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Misc/cdmatch2')
-rw-r--r--Functions/Misc/cdmatch215
1 files changed, 15 insertions, 0 deletions
diff --git a/Functions/Misc/cdmatch2 b/Functions/Misc/cdmatch2
new file mode 100644
index 000000000..8a3e9591f
--- /dev/null
+++ b/Functions/Misc/cdmatch2
@@ -0,0 +1,15 @@
+# This function should be called from compctl to complete the
+# second argument of cd and pushd.
+
+emulate -R zsh				# Requires zsh 3.0-pre4 or later
+setopt localoptions extendedglob
+local from
+
+read -Ac from
+from="${from[2]}"
+
+eval "reply=( \${PWD:s@$from@$1*$2@}~$PWD(ND-/:) )"
+reply=( "${${reply[@]#${PWD%%$from*}}%${PWD#*$from}}" )
+[[ ${#reply[(r),-1]} != 0 ]] && reply[(r)]="''"
+
+return