Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[patch] Add ldap completer
- X-seq: zsh-workers 43064
- From: Matthew Martin <phy1729@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [patch] Add ldap completer
- Date: Tue, 19 Jun 2018 07:57:23 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=UYiyyxAeyE9NOBCYmlKlVo9YbwaLtajvTZ8SzFjC/JI=; b=sLlclMXCFm/U66fMJ2zpoCBeM4yZae42SqRCyUizyKbhRX4ZV6aU0S0q8lgXfE1wzX pBD245q7qnseK34t3yDigs9airah3MI/ZM5qduI0cwnS/NpOXmQe7mgBQZrDa01zRskA 1K3v0z7wlw8TPcw3w2FG2wkIIuDKygevlzwcYUiLgP6qC9bZHcv96wMCOhv6RD5wca4Z ohna8G8LKwNq86914cZ6fhS9doTMNW9YeHvyfUcezF4Pyv3hmUDfahDlOX84ekuxBUBu f4G7CewwWgG2QEJJGEZYiPzDEJAwKHM6IBoVGXNCO/Qxo5p6PBh1Rie6Uq1/plf6cslk MaMQ==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
OpenBSD recently gained an ldap command. This is my first stab at
completing it.
For the protocol _describe, is -I correct? I don't grok the differences
between the prefixes and suffixes. For host is -S '' correct for not
adding a space after and should the completer avoid adding the space?
The ldapi protocol is not completed correctly because I don't know how
to make _files replace / with %2f.
(N.B. The URL pattern below is correct by RFC, I'll submit a patch for
the OpenBSD man page soon.)
- Matthew Martin
diff --git a/Completion/BSD/Command/_ldap b/Completion/BSD/Command/_ldap
new file mode 100644
index 000000000..ba8b981b4
--- /dev/null
+++ b/Completion/BSD/Command/_ldap
@@ -0,0 +1,79 @@
+#compdef ldap
+
+local -a commands scopes
+commands=(
+ search:'search a directory'
+)
+scopes=(
+ base:'base object only'
+ one:'one level'
+ sub:subtree
+)
+
+_ldap_url() {
+ local -a expl protocols 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)
+ fi
+
+ if ! compset -P '*/'; then
+ if compset -P '*:'; then
+ tags=(port)
+ else
+ tags+=(host)
+ fi
+ else
+ case $PREFIX in
+ *\?*\?*\?*) tags=(filter);;
+ *\?*\?*) tags=(scope);;
+ *\?*) tags=(attribute);;
+ *) tags=(basedn);;
+ esac
+ compset -P '*\?'
+ fi
+
+ _tags $tags
+ while _tags; do
+ _requested protocol && _describe -t protocol protocol protocols -I ://
+ _requested host && _hosts -S ''
+ _requested port && _guard '|<1-65535>' port
+ _requested basedn expl 'base DN'
+ _requested attribute expl attribute
+ _requested scope && _describe -t scope scope scopes
+ _requested filter expl filter
+ 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]:' \
+ ':: :_guard "*=*" "filter"' \
+ '*:attribute:'
+ ;;
+ esac
+fi
Messages sorted by:
Reverse Date,
Date,
Thread,
Author