1 # original by Alfredo Esteban <aedelatorre at xxxxxxxxx>
2 # (http://www.spinics.net/lists/linux-btrfs/msg15899.html)
3 # edited by Joseph Wang <joequant at gmail.com>
4 # (http://lists.alioth.debian.org/pipermail/bash-completion-devel/2013-June/004868.html)
5 # edited by John C F <john.ch.fr at gmail.com> on 2015-02-02
10 DEVS=''; while read dev; do DEVS+="$dev "; done < <(lsblk -pnro name)
11 COMPREPLY+=( $( compgen -W "$DEVS" -- "$cur" ) )
18 while read mnt; do MNTS+="$mnt "
19 done < <(mount | awk '{print $3}')
20 COMPREPLY+=( $( compgen -W "$MNTS" -- "$cur" ) )
25 local cur prev words cword
26 _init_completion || return
32 commands='subvolume filesystem balance device scrub check rescue restore inspect-internal property send receive quota qgroup replace help version'
33 commands_subvolume='create delete list snapshot find-new get-default set-default show sync'
34 commands_filesystem='defragment sync resize show df label usage'
35 commands_balance='start pause cancel resume status'
36 commands_device='scan add delete remove ready stats usage'
37 commands_scrub='start cancel resume status'
38 commands_rescue='chunk-recover super-recover'
39 commands_inspect_internal='inode-resolve logical-resolve subvolid-resolve rootid min-dev-size dump-tree dump-super tree-stats'
40 commands_property='get set list'
41 commands_quota='enable disable rescan'
42 commands_qgroup='assign remove create destroy show limit'
43 commands_replace='start status cancel'
45 if [[ "$cur" == -* && $cword -le 3 && "$cmd" != "help" ]]; then
46 COMPREPLY=( $( compgen -W '--help' -- "$cur" ) )
50 if [[ $cword -eq 1 ]]; then
51 COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
53 elif [[ $cword -eq 2 ]]; then
56 opts="$commands_subvolume"
59 opts="$commands_filesystem"
62 opts="$commands_balance"
65 opts="$commands_device"
68 opts="$commands_scrub"
75 opts="$commands_rescue"
82 opts="$commands_inspect_internal"
85 opts="$commands_property"
92 opts="$commands_quota"
95 opts="$commands_qgroup"
98 opts="$commands_replace"
107 COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
109 elif [[ $cword -eq 3 ]]; then
143 if [[ "$cmd" == "receive" && "$prev" == "-f" ]]; then
152 complete -F _btrfs btrfs