summarylogtreecommitdiffstats
path: root/zshcomp.patch
blob: aae7debcca3d6eab309465f9f0b8db10f924240b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
--- modules-tcl-1.832/init/zsh.in	2017-04-29 08:23:22.000000000 +0200
+++ modules-tcl-1.832-patched/init/zsh.in	2017-05-07 18:41:21.812267826 +0200
@@ -83,3 +83,48 @@
 if [ -r @initdir@/modulerc -a "$MODULEPATH" = '' -a "$LOADEDMODULES" = '' ]; then
    source @initdir@/modulerc
 fi
+
+# zsh-completion function, improves the standard zsh-completion (_module):
+#  - support for symlinks
+#  - directory-wise completion
+function _module_completion () {
+    local _module_path_prefix
+    local -a _module_search_path _module_type_d _module_type_f
+    _module_path_prefix=$(echo ${words[$CURRENT]} | sed -ne 's#\(.*/\).*#\1#p')
+    _module_search_paths=(${^${(@s/:/)MODULEPATH}}/$_module_path_prefix)
+
+    _module_type_d=()
+    _module_type_f=()
+    eval $(find $_module_search_paths -mindepth 1 -maxdepth 1 -not -name '.modulerc' -not -name '.version' -printf "_module_type_%Y+=${_module_path_prefix}%P\n" 2> /dev/null)
+
+    if [[ "$@" != "dir" ]]; then
+        compadd -q -S / ${_module_type_d}
+        compadd ${_module_type_f}
+    else
+        compadd ${_module_type_d}
+    fi
+}
+
+# module avail should only complete directories
+function _module_avail {
+    _module_completion dir
+}
+
+# all the other use the full completion:
+local -a _module_complete_functions=( \
+        _module_help \
+        _module_load \
+        _module_switch \
+        _module_display \
+        _module_whatis \
+        _module_initadd \
+        _module_initprepend \
+        _module_initrm \
+        _module_initswitch \
+)
+
+for _module_complete_function in $_module_complete_functions ; do
+    $_module_complete_function () {
+        _module_completion
+    }
+done
+
+# vim: syntax=zsh