Whamcloud - gitweb
LU-12734 misc: add bash completion for lctl set/get_param
[fs/lustre-release.git] / lustre / scripts / bash-completion / lctl
1 _lctl()
2 {
3         local cur prev words cword
4
5         _init_completion || return
6         COMPREPLY=()
7
8         if [[ "$cword" == "1" ]]; then
9                 COMPREPLY=( $( compgen -W '$(lctl --list-commands |
10                                              grep -v '^=')' -- "$cur" ) )
11                 return 0
12         fi
13
14         case "${words[1]}" in
15         set_param|list_param|get_param)
16                 local filter="s/=$//"
17                 [[ "${words[1]}" == "set_param" ]] && filter="/[^=/]$/d"
18                 mapfile -t COMPREPLY < <(
19                     lctl list_param -F "${cur#[\"\']}*" 2>/dev/null |
20                     sed -e "$filter" -e 's#/$#.#' \
21                         -e "s#^${cur//\*/[^.]*}#$cur#"
22                     )
23                 compopt -o nospace
24
25                 return 0
26                 ;;
27         esac
28 } &&
29 complete -F _lctl lctl