6 # "--list-command" prints commands in columns and truncates long ones
7 "$cmd" "$sub" --non-existent-option |
8 sed -e 1d -e '$d' -e 's/"//g' -e /=/d -e /exit/d -e /quit/d
17 # strip off usage message decoration and leave long opts
18 if [[ -n "$subsub" ]]; then
19 "$cmd" "$sub" help "$subsub" |& grep -owE -- '--[-a-zA-Z0]*'
21 "$cmd" help "$sub" |& sed -e 1d | grep -owE -- '--[-a-zA-Z0]*'
23 # several commands take the same options as setstripe, except --delete
25 migrate|mirrorcreate|mirrorextend)
26 _lustre_long_opts "$cmd" setstripe | grep -v -- --delete
36 # strip off usage message decoration and leave short opts
37 if [[ -n "$subsub" ]]; then
38 "$cmd" "$sub" help "$subsub" |& grep -owE -- '-[-a-zA-Z0]'
40 "$cmd" help "$sub" |& grep -owE -- '-[-a-zA-Z0]'
42 # several commands take the same options as setstripe, except -d
44 migrate|mirrorextend|mirrorextend)
45 _lustre_short_opts "$cmd" setstripe | grep -v -- -d
54 flags=$("$cmd" help find |& tr "<>[],}" " " |
55 grep -- '--component-flags {' | cut -d\{ -f2)
56 if [[ -z "$flags" ]]; then
57 local version=($("$cmd" --version))
59 case "${version[1]}" in
60 2.13*) flags="init stale prefer offline nosync extension";;
61 2.12*|2.11*) flags="init stale prefer offline nosync";;
70 findmnt --list -t lustre -n -o TARGET
73 _lustre_mount_fsnames()
77 # FIXME: will fail if newlines in $mountpoint, why would anyone do that?
78 _lustre_mountpoints | while read mountpoint; do
79 lfs getname -n "$mountpoint" 2> /dev/null
85 lctl device_list | awk '{ print $4 }'
90 local mountpoint="${1:-'.'}"
92 local fsname=$(lfs getname -n "$mountpoint" 2>/dev/null)
94 [[ -n "$fsname" ]] && echo "$fsname" || _lustre_mount_fsnames
99 "$cmd" help find |& tr "[]," " " | grep -- --layout | sed "s/.*-L //"
104 lfs mdts $1 | grep _UUID | sed -e "s/[0-9]*: //" -e "s/_UUID.*//"
109 lfs osts $1 | grep _UUID | sed -e "s/[0-9]*: //" -e "s/_UUID.*//"
114 if [[ -d "$1" ]]; then
115 "$cmd" pool_list $1 2> /dev/null | grep -v "[Pp]ools from" |
120 for fsname in $(_lustre_fsnames $1); do
121 "$cmd" pool_list $fsname 2> /dev/null | grep -v "[Pp]ools from"
127 local cur prev words cword
128 local mountpoint cmd sub find_opts
131 # allow different versions of bash_completion to work
132 if declare -F _init_completion > /dev/null; then
133 # this provides more functionality, but is only in v2.x
134 _init_completion || return
136 # this is compatible with both v1.3 and v2.x
137 _get_comp_words_by_ref cur prev words cword
142 [[ "$sub" == "mirror" || "$sub" == "pcc" ]] && subsub="${words[2]}"
143 if [[ "$cword" == "1" || "$prev" == "help" ]]; then
144 COMPREPLY+=($(compgen -W '$(_lustre_cmds "$cmd")' -- "$cur"))
150 COMPREPLY+=($(compgen -W '$(_lustre_long_opts "$cmd" "$sub" "$subsub")' -- "$cur"))
154 # lfs find allows "-longopt" for compatibility with find(1)
155 [[ "$sub" == "find" ]] && find_opts=$(_lustre_long_opts "$cmd" find)
156 COMPREPLY+=($(compgen -W '$(_lustre_short_opts "$cmd" "$sub" "$subsub") ${find_opts//--/-}' -- "$cur"))
163 [[ -n "$cur" ]] && return 0
164 COMPREPLY+=($(compgen -W '$("$cmd" help check |& grep usage |
165 sed -e "s/[<>|]/ /g" \
166 -e "s/.*check //")' -- "$cur"))
170 mapfile -t COMPREPLY < <(
171 _lustre_mountpoints | grep -- "^$cur" | sed 's/ /\\ /g'
176 [[ -d "${words[2]}" ]] && mountpoint="${words[2]}"
177 case "${prev/--/-}" in
178 -component-flags|-comp-flags)
179 # FIXME: this should allow a comma-separated list
180 COMPREPLY+=($(compgen -W '$(_lustre_comp_flags)' -- "$cur"))
184 COMPREPLY+=($(compgen -g -- "$cur"))
188 COMPREPLY+=($(compgen -W '$(_lustre_layouts)' -- "$cur"))
192 # FIXME: this should allow a comma-separated list
193 COMPREPLY+=($(compgen -W '$(_lustre_mdts "$mountpoint")' -- "$cur"))
197 # FIXME: this should allow a comma-separated list
198 COMPREPLY+=($(compgen -W '$(_lustre_osts "$mountpoint")' -- "$cur"))
202 COMPREPLY+=($(compgen -W '$(_lustre_pools "$mountpoint")' -- "$cur"))
206 COMPREPLY+=($(compgen -W 'b c d f l p s' -- "$cur"))
210 COMPREPLY+=($(compgen -u -- "$cur"))
214 if [ -z "$mountpoint" ]; then
215 mapfile -t COMPREPLY < <(
216 _lustre_mountpoints | grep -- "^$cur" |
223 if [[ "$prev" == "$sub" ]]; then
224 COMPREPLY+=($(compgen -W '$(_lustre_cmds "$cmd" "$sub")' -- "$cur"))
229 if [[ "$prev" == "$sub" ]]; then
230 COMPREPLY+=($(compgen -W '$(_lustre_cmds "$cmd" "$sub")' -- "$cur"))
235 COMPREPLY+=($(compgen -W '$(_lustre_fsnames
236 _lustre_pools)' -- "$cur"))
241 --component-flags|--comp-flags)
242 # only subset allowed, easier to list than exclude for now
243 # COMPREPLY+=($(compgen -W '$(_lustre_comp_flags)' -- "$cur"))
244 # FIXME: this should allow a comma-separated list
245 COMPREPLY+=($(compgen -W 'nosync prefer' -- "$cur"))
249 COMPREPLY+=($(compgen -W '$(_lustre_pools)' -- "$cur"))
263 local cur prev words cword
266 # allow different versions of bash_completion to work
267 if declare -F _init_completion > /dev/null; then
268 # this provides more functionality, but is only in v2.x
269 _init_completion || return
271 # this is compatible with both v1.3 and v2.x
272 _get_comp_words_by_ref cur prev words cword
277 [[ "$sub" == "--device" && $cword -ge 4 ]] && sub="${words[3]}"
279 if [[ "$cword" == "1" || "$prev" == "help" ]]; then
280 COMPREPLY+=($(compgen -W '$(_lustre_cmds "$cmd")' -- "$cur"))
286 COMPREPLY+=($(compgen -W '$(_lustre_long_opts "$cmd" "$sub")' -- "$cur"))
290 COMPREPLY+=($(compgen -W '$(_lustre_short_opts "$cmd" "$sub")' -- "$cur"))
297 if [[ "$cword" == "2" ]]; then
298 COMPREPLY+=($(compgen -W '$(_lustre_devices)' -- "$cur"))
299 elif [[ "$cword" == "3" ]]; then
300 COMPREPLY+=($(compgen -W '$(_lustre_cmds "$cmd")' -- "$cur"))
304 get_param|list_param|set_param)
305 local filter="s/=$//"
306 [[ "$sub" == "set_param" ]] && filter="/[^=/]$/d"
307 mapfile -t COMPREPLY < <(
308 "$cmd" list_param -F "${cur#[\"\']}*" 2>/dev/null |
309 sed -e "$filter" -e 's#/$#.#' \
310 -e "s#^${cur//\*/[^.]*}#$cur#"
317 if [[ "$prev" == "$sub" ]]; then
318 COMPREPLY+=($(compgen -W '$(_lustre_cmds "$cmd" "$sub")' -- "$cur"))
323 if [[ "$cword" == "2" ]]; then
324 COMPREPLY+=($(compgen -W '$(_lustre_mountpoints
326 _lustre_pools)' -- "$cur"))
331 if [[ "$cword" == "2" ]]; then
332 COMPREPLY+=($(compgen -W '$(_lustre_pools)' -- "$cur"))
337 pool_add|pool_remove)
338 if [[ "$cword" == "2" ]]; then
339 COMPREPLY+=($(compgen -W '$(_lustre_pools)' -- "$cur"))
341 elif [[ "$cword" == "3" ]]; then
342 COMPREPLY+=($(compgen -W '$(_lustre_osts)' -- "$cur"))
349 complete -F _lctl lctl