-
Notifications
You must be signed in to change notification settings - Fork 1
/
ldap.auto
executable file
·74 lines (68 loc) · 2.92 KB
/
ldap.auto
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
# -------------------------------------------------------------------------------
#
# Copyright (c) 2016 Slava Vladyshevsky. All rights reserved.
# Licensed under the MIT License. See LICENSE file in the project root.
#
# Author: Slava Vladyshevsky <slava.vladyshevsky(a)gmail.com>
# Project: DevOps Automation
#
# Bash auto-completion for the ldap tool
#
# -------------------------------------------------------------------------------
# see https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html
# $1: is the name of the command whose arguments are being completed
# $2: is the word being completed, equal to ${COMP_WORDS[COMP_CWORD]}
# $3: is the word preceding the word being completed, equal to ${COMP_WORDS[COMP_CWORD-1]}
_comp_ldap() {
# the basic CLI objects
local objects="group org user"
local args=""
COMPREPLY=()
if [[ "${1} ${objects}" =~ ${3} ]] ; then
case "${3}" in
group) args="list dir add create del remove users members adduser useradd deluser userdel" ;;
org) args="list dir add create del remove" ;;
user) args="list dir groups memberof add create del remove getattr setattr" ;;
${1}) args=${objects} ;;
*) return 0 ;;
esac
else
case "${COMP_WORDS[1]}-${COMP_WORDS[2]}" in
group-list|group-dir) args="--org --format" ;;
group-add|group-create) args="--org --group" ;;
group-del|group-remove) args="--org --group" ;;
group-users|group-members) args="--group --format" ;;
group-adduser|group-useradd) args="--group --org --name" ;;
group-deluser|group-userdel) args="--group --org --name" ;;
org-list|org-dir) args="--pattern --format" ;;
org-add|org-create) args="--org" ;;
org-del|org-remove) args="--org" ;;
user-groups|user-memberof) args="--org --name --format" ;;
user-list|user-dir) args="--org --container --format" ;;
user-add|user-create) args="--org --container --first --last --login --mail --password" ;;
user-del|user-remove) args="--org --name" ;;
user-getattr) args="--org --name --attr" ;;
user-setattr) args="--org --name --attr --value" ;;
*) return 0 ;;
esac
fi
# complete the choice for some of the common arguments
if [[ ${3} == --* ]] ; then
local IFS=$'\n\t'
case "${3}" in
--container) args=$'Users\tGroups\tService Accounts' ;;
--org) args=$(${1} org list 2>/dev/null) ;;
--group) args=$(${1} group list 2>/dev/null) ;;
--format) args=$'short\tlong' ;;
*) return 0 ;;
esac
COMPREPLY=($(compgen -W "${args[*]}" -- ${2}))
# escaping spaces and other unsafe characters
COMPREPLY=($(printf "%q\n" "${COMPREPLY[@]}"))
return 0
fi
COMPREPLY=($(compgen -W "${args[*]}" -- ${2}))
return 0
}
complete -F _comp_ldap ldap