-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathldaps_completion
More file actions
49 lines (43 loc) · 1.17 KB
/
Copy pathldaps_completion
File metadata and controls
49 lines (43 loc) · 1.17 KB
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
# -*- shell-script -*-
# bash-completion for ldaps utility
#
# first arg (two char minimum) completes to usernames
# rest of args complete to attr names
#
# include in your ~/.bashrc (only takes effect if ldaps is
# in your $PATH):
#
# source /path/to/ldaps_completion
#
# or install into /etc/bash_completion.d/
_ldaps() {
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ $COMP_CWORD > 1 ]]; then
# list of attributes
case "$prev" in
*)
COMPREPLY=( $(compgen -W \
"$(ldaps ${COMP_WORDS[1]}\* | perl -nle 'm/^([^#][^:]+):/ and print lc $1')" \
-- $cur) )
return 0
;;
esac
fi
# username
case "$cur" in
[a-zA-Z][a-zA-Z]*)
COMPREPLY=( $(compgen -W \
"$(ldaps ${cur}\* samaccountname | awk '/^sAMAccountName:/ { print tolower($2) }')" \
-- $cur) )
return 0
;;
esac
return 0
}
# autocomplete for ldaps utility
if [ -n "$(which ldaps)" ]; then
complete -F _ldaps ldaps
fi