about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Martin <phy1729@gmail.com>2018-07-07 14:47:46 -0500
committerMatthew Martin <phy1729@gmail.com>2018-07-07 14:47:46 -0500
commita37d92524740112c96a0d843d4f2c885b0d399ec (patch)
treefa262d5854d2bed437255a299d167f054b651c2c
parent6fe0c24fdbe0444df91a11794532752fc56c78db (diff)
downloadzsh-a37d92524740112c96a0d843d4f2c885b0d399ec.tar.gz
zsh-a37d92524740112c96a0d843d4f2c885b0d399ec.tar.xz
zsh-a37d92524740112c96a0d843d4f2c885b0d399ec.zip
43106: Add ldap completer
-rw-r--r--ChangeLog4
-rw-r--r--Completion/BSD/Command/_ldap87
2 files changed, 91 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index f57dbec82..33cae5502 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2018-07-07  Matthew Martin  <phy1729@gmail.com>
+
+	* 43106: Completion/BSD/Command/_ldap: Add ldap completer.
+
 2018-07-03  dana  <dana@dana.is>
 
 	* 43105 (tweaked): Completion/Unix/Command/_pgrep: Add full procps
diff --git a/Completion/BSD/Command/_ldap b/Completion/BSD/Command/_ldap
new file mode 100644
index 000000000..8fa17e2f8
--- /dev/null
+++ b/Completion/BSD/Command/_ldap
@@ -0,0 +1,87 @@
+#compdef ldap
+
+local -a commands scopes
+commands=(
+  search:'search a directory'
+)
+scopes=(
+  base:'base object only'
+  one:'one level'
+  sub:subtree
+)
+
+_ldap_url() {
+  local nm=$compstate[nmatches]
+  local -a expl protocols suf_proto suf_scope tags
+  protocols=(
+    ldap:'TCP in plaintext'
+    ldaps:'TLS'
+    ldap+tls:'TCP and use StartTLS'
+    ldapi:'connect to a socket'
+  )
+
+  # [protocol://]host[:port][/basedn[?[attribute,...][?[scope][?[filter]]]]]
+  if ! compset -P '*://'; then
+    tags=(protocol)
+    compset -S ':*' || suf_proto=( -S :// )
+  fi
+
+  if ! compset -P '*/'; then
+    if compset -P '*:'; then
+      tags=(port)
+      compset -S '/*'
+    else
+      if ! compset -S '://*'; then
+        tags+=(host)
+        compset -S '[:/]*'
+      fi
+    fi
+  else
+    case $PREFIX in
+      *\?*\?*\?*) tags=(filter);;
+      *\?*\?*) tags=(scope); [[ -suffix \?* ]] || suf_scope=( -qS \? );;
+      *\?*) tags=(attribute);;
+      *) tags=(basedn);;
+    esac
+    compset -P '*\?'
+    compset -S '\?*'
+  fi
+
+  _tags $tags
+  while _tags; do
+    _requested protocol && _describe -t protocol protocol protocols $suf_proto
+    _requested host && _hosts -S ''
+    _requested port expl port
+    _requested basedn expl 'base DN'
+    _requested attribute expl attribute
+    _requested scope && _describe -t scope scope scopes $suf_scope
+    _requested filter expl filter
+    [[ nm -ne compstate[nmatches] ]] && return 0
+  done
+}
+
+if (( CURRENT == 2 )); then
+  _describe command commands
+else
+  shift words; (( CURRENT-- ))
+  case $words[1] in
+    search)
+      _arguments -s -S -A '-*' \
+        '-b+[specify base DN]:base DN:' \
+        '-c+[specify CA file]:CA file:' \
+        '-D+[specify bind DN]:bind DN:' \
+        '-H+[specify URL]: :_ldap_url' \
+        '-L[output in LDIF]' \
+        '-l+[specify time limit or 0 for no limit]:time limit [0]:' \
+        '-s+[specify scope]:scope [sub]:(($scopes))' \
+        '-v[be verbose]' \
+        '-W[prompt for bind secret]' \
+        '-w+[specify bind secret]:bind secret:' \
+        '-x[use simple authentication]' \
+        '-Z[use StartTLS]' \
+        '-z+[specify maximum number of results or 0 for no limit]:size limit [0]:' \
+        '::filter:' \
+        '*:attribute:'
+      ;;
+  esac
+fi