6 $cmd $sub --list-commands |
7 sed -e '/=/d' -e s/exit// -e s/quit//
16 # strip off usage message decoration and leave long opts
17 if [[ -n "$subsub" ]]; then
18 "$cmd" "$sub" help "$subsub" |& grep -owE -- '--[-a-zA-Z0]*'
20 "$cmd" help "$sub" |& sed -e 1d | grep -owE -- '--[-a-zA-Z0]*'
22 # several commands take the same options as setstripe, except --delete
24 migrate|mirrorcreate|mirrorextend)
25 _lustre_long_opts "$cmd" setstripe | grep -v -- --delete
35 # strip off usage message decoration and leave short opts
36 if [[ -n "$subsub" ]]; then
37 "$cmd" "$sub" help "$subsub" |& grep -owE -- '-[-a-zA-Z0]'
39 "$cmd" help "$sub" |& grep -owE -- '-[-a-zA-Z0]'
41 # several commands take the same options as setstripe, except -d
43 migrate|mirrorextend|mirrorextend)
44 _lustre_short_opts "$cmd" setstripe | grep -v -- -d
53 flags=$("$cmd" help find |& tr "<>[],}" " " |
54 grep -- '--component-flags {' | cut -d\{ -f2)
55 if [[ -z "$flags" ]]; then
56 local version=($("$cmd" --version))
58 case "${version[1]}" in
59 2.13*) flags="init stale prefer offline nosync extension";;
60 2.12*|2.11*) flags="init stale prefer offline nosync";;
69 findmnt --list -t lustre -n -o TARGET
72 _lustre_mount_fsnames()
76 # FIXME: will fail if newlines in $mountpoint, why would anyone do that?
77 _lustre_mountpoints | while read mountpoint; do
78 lfs getname -n "$mountpoint" 2> /dev/null
84 lctl device_list | awk '{ print $4 }'
89 local mountpoint="${1:-'.'}"
91 local fsname=$(lfs getname -n "$mountpoint" 2>/dev/null)
93 [[ -n "$fsname" ]] && echo "$fsname" || _lustre_mount_fsnames
98 "$cmd" help find |& tr "[]," " " | grep -- --layout | sed "s/.*-L //"
103 lfs mdts $1 | grep _UUID | sed -e "s/[0-9]*: //" -e "s/_UUID.*//"
108 lfs osts $1 | grep _UUID | sed -e "s/[0-9]*: //" -e "s/_UUID.*//"
113 if [[ -d "$1" ]]; then
114 "$cmd" pool_list $1 2> /dev/null | grep -v "[Pp]ools from" |
119 for fsname in $(_lustre_fsnames $1); do
120 "$cmd" pool_list $fsname 2> /dev/null | grep -v "[Pp]ools from"
126 local cur prev words cword
127 local mountpoint cmd sub find_opts
130 # allow different versions of bash_completion to work
131 if declare -F _init_completion > /dev/null; then
132 # this provides more functionality, but is only in v2.x
133 _init_completion || return
135 # this is compatible with both v1.3 and v2.x
136 _get_comp_words_by_ref cur prev words cword
141 [[ "$sub" == "mirror" || "$sub" == "pcc" ]] && subsub="${words[2]}"
142 if [[ "$cword" == "1" || "$prev" == "help" ]]; then
143 COMPREPLY+=($(compgen -W '$(_lustre_cmds "$cmd")' -- "$cur"))
149 COMPREPLY+=($(compgen -W '$(_lustre_long_opts "$cmd" "$sub" "$subsub")' -- "$cur"))
153 # lfs find allows "-longopt" for compatibility with find(1)
154 [[ "$sub" == "find" ]] && find_opts=$(_lustre_long_opts "$cmd" find)
155 COMPREPLY+=($(compgen -W '$(_lustre_short_opts "$cmd" "$sub" "$subsub") ${find_opts//--/-}' -- "$cur"))
162 [[ -n "$cur" ]] && return 0
163 COMPREPLY+=($(compgen -W '$("$cmd" help check |& grep usage |
164 sed -e "s/[<>|]/ /g" \
165 -e "s/.*check //")' -- "$cur"))
169 mapfile -t COMPREPLY < <(
170 _lustre_mountpoints | grep -- "^$cur" | sed 's/ /\\ /g'
175 [[ -d "${words[2]}" ]] && mountpoint="${words[2]}"
176 case "${prev/--/-}" in
177 -component-flags|-comp-flags)
178 # FIXME: this should allow a comma-separated list
179 COMPREPLY+=($(compgen -W '$(_lustre_comp_flags)' -- "$cur"))
183 COMPREPLY+=($(compgen -g -- "$cur"))
187 COMPREPLY+=($(compgen -W '$(_lustre_layouts)' -- "$cur"))
191 # FIXME: this should allow a comma-separated list
192 COMPREPLY+=($(compgen -W '$(_lustre_mdts "$mountpoint")' -- "$cur"))
196 # FIXME: this should allow a comma-separated list
197 COMPREPLY+=($(compgen -W '$(_lustre_osts "$mountpoint")' -- "$cur"))
201 COMPREPLY+=($(compgen -W '$(_lustre_pools "$mountpoint")' -- "$cur"))
205 COMPREPLY+=($(compgen -W 'b c d f l p s' -- "$cur"))
209 COMPREPLY+=($(compgen -u -- "$cur"))
213 if [ -z "$mountpoint" ]; then
214 mapfile -t COMPREPLY < <(
215 _lustre_mountpoints | grep -- "^$cur" |
222 if [[ "$prev" == "$sub" ]]; then
223 COMPREPLY+=($(compgen -W '$(_lustre_cmds "$cmd" "$sub")' -- "$cur"))
228 if [[ "$prev" == "$sub" ]]; then
229 COMPREPLY+=($(compgen -W '$(_lustre_cmds "$cmd" "$sub")' -- "$cur"))
234 COMPREPLY+=($(compgen -W '$(_lustre_fsnames
235 _lustre_pools)' -- "$cur"))
240 --component-flags|--comp-flags)
241 # only subset allowed, easier to list than exclude for now
242 # COMPREPLY+=($(compgen -W '$(_lustre_comp_flags)' -- "$cur"))
243 # FIXME: this should allow a comma-separated list
244 COMPREPLY+=($(compgen -W 'nosync prefer' -- "$cur"))
248 COMPREPLY+=($(compgen -W '$(_lustre_pools)' -- "$cur"))
262 local cur prev words cword
265 # allow different versions of bash_completion to work
266 if declare -F _init_completion > /dev/null; then
267 # this provides more functionality, but is only in v2.x
268 _init_completion || return
270 # this is compatible with both v1.3 and v2.x
271 _get_comp_words_by_ref cur prev words cword
276 [[ "$sub" == "--device" && $cword -ge 4 ]] && sub="${words[3]}"
278 if [[ "$cword" == "1" || "$prev" == "help" ]]; then
279 COMPREPLY+=($(compgen -W '$(_lustre_cmds "$cmd")' -- "$cur"))
285 COMPREPLY+=($(compgen -W '$(_lustre_long_opts "$cmd" "$sub")' -- "$cur"))
289 COMPREPLY+=($(compgen -W '$(_lustre_short_opts "$cmd" "$sub")' -- "$cur"))
296 if [[ "$cword" == "2" ]]; then
297 COMPREPLY+=($(compgen -W '$(_lustre_devices)' -- "$cur"))
298 elif [[ "$cword" == "3" ]]; then
299 COMPREPLY+=($(compgen -W '$(_lustre_cmds "$cmd")' -- "$cur"))
303 get_param|list_param|set_param)
304 local filter="s/=$//"
305 [[ "$sub" == "set_param" ]] && filter="/[^=/]$/d"
306 mapfile -t COMPREPLY < <(
307 "$cmd" list_param -F "${cur#[\"\']}*" 2>/dev/null |
308 sed -e "$filter" -e 's#/$#.#' \
309 -e "s#^${cur//\*/[^.]*}#$cur#"
316 if [[ "$prev" == "$sub" ]]; then
317 COMPREPLY+=($(compgen -W '$(_lustre_cmds "$cmd" "$sub")' -- "$cur"))
322 if [[ "$cword" == "2" ]]; then
323 COMPREPLY+=($(compgen -W '$(_lustre_mountpoints
325 _lustre_pools)' -- "$cur"))
330 if [[ "$cword" == "2" ]]; then
331 COMPREPLY+=($(compgen -W '$(_lustre_pools)' -- "$cur"))
336 pool_add|pool_remove)
337 if [[ "$cword" == "2" ]]; then
338 COMPREPLY+=($(compgen -W '$(_lustre_pools)' -- "$cur"))
340 elif [[ "$cword" == "3" ]]; then
341 COMPREPLY+=($(compgen -W '$(_lustre_osts)' -- "$cur"))
348 complete -F _lctl lctl