Whamcloud - gitweb
e471e18f053cf043a63591512460efbc8d041547
[fs/lustre-release.git] / lustre / scripts / bash-completion / lctl
1 _lctl()
2 {
3         local cur prev words cword
4
5         COMPREPLY=()
6         # allow different versions of bash_completion to work
7         if declare -F _init_completion > /dev/null; then
8                 # this provides more functionality, but is only in v2.x
9                 _init_completion || return
10         else
11                 # this is compatible with both v1.3 and v2.x
12                 _get_comp_words_by_ref -n : cur prev words cword
13         fi
14
15         if [[ "$cword" == "1" ]]; then
16                 COMPREPLY=( $( compgen -W '$(lctl --list-commands |
17                                              grep -v '^=')' -- "$cur" ) )
18                 return 0
19         fi
20
21         case "${words[1]}" in
22         set_param|list_param|get_param)
23                 local filter="s/=$//"
24                 [[ "${words[1]}" == "set_param" ]] && filter="/[^=/]$/d"
25                 mapfile -t COMPREPLY < <(
26                     lctl list_param -F "${cur#[\"\']}*" 2>/dev/null |
27                     sed -e "$filter" -e 's#/$#.#' \
28                         -e "s#^${cur//\*/[^.]*}#$cur#"
29                     )
30                 compopt -o nospace
31
32                 return 0
33                 ;;
34         esac
35 } &&
36 complete -F _lctl lctl