2015-02-03 00:49:41 +08:00
|
|
|
# original by Alfredo Esteban <aedelatorre at xxxxxxxxx>
|
|
|
|
# (http://www.spinics.net/lists/linux-btrfs/msg15899.html)
|
|
|
|
# edited by Joseph Wang <joequant at gmail.com>
|
|
|
|
# (http://lists.alioth.debian.org/pipermail/bash-completion-devel/2013-June/004868.html)
|
|
|
|
# edited by John C F <john.ch.fr at gmail.com> on 2015-02-02
|
|
|
|
|
|
|
|
_btrfs_mnts()
|
|
|
|
{
|
|
|
|
local MNTS
|
|
|
|
MNTS=''
|
|
|
|
while read mnt; do MNTS+="$mnt "
|
2017-09-11 13:22:43 +08:00
|
|
|
done < <(mount -t btrfs | awk '{print $3}')
|
2015-02-03 00:49:41 +08:00
|
|
|
COMPREPLY+=( $( compgen -W "$MNTS" -- "$cur" ) )
|
|
|
|
}
|
|
|
|
|
2016-02-22 22:49:50 +08:00
|
|
|
_btrfs()
|
2015-02-03 00:49:41 +08:00
|
|
|
{
|
|
|
|
local cur prev words cword
|
2017-09-12 09:04:10 +08:00
|
|
|
_init_completion || return
|
2015-02-03 00:49:41 +08:00
|
|
|
|
2017-09-12 09:04:10 +08:00
|
|
|
COMPREPLY=()
|
2016-02-22 22:49:50 +08:00
|
|
|
|
2015-02-03 00:49:41 +08:00
|
|
|
local cmd=${words[1]}
|
|
|
|
|
2017-09-12 09:04:10 +08:00
|
|
|
commands='subvolume filesystem balance device scrub check rescue restore inspect-internal property send receive quota qgroup replace help version'
|
|
|
|
commands_subvolume='create delete list snapshot find-new get-default set-default show sync'
|
|
|
|
commands_filesystem='defragment sync resize show df du label usage'
|
|
|
|
commands_balance='start pause cancel resume status'
|
|
|
|
commands_device='scan add delete remove ready stats usage'
|
|
|
|
commands_scrub='start cancel resume status'
|
2020-10-30 07:17:36 +08:00
|
|
|
commands_rescue='chunk-recover super-recover zero-log create-control-device'
|
2017-09-12 09:04:10 +08:00
|
|
|
commands_inspect_internal='inode-resolve logical-resolve subvolid-resolve rootid min-dev-size dump-tree dump-super tree-stats'
|
|
|
|
commands_property='get set list'
|
|
|
|
commands_quota='enable disable rescan'
|
|
|
|
commands_qgroup='assign remove create destroy show limit'
|
|
|
|
commands_replace='start status cancel'
|
2015-02-03 00:49:41 +08:00
|
|
|
|
|
|
|
if [[ "$cur" == -* && $cword -le 3 && "$cmd" != "help" ]]; then
|
|
|
|
COMPREPLY=( $( compgen -W '--help' -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2017-09-12 09:04:10 +08:00
|
|
|
if [[ $cword -eq 1 ]]; then
|
|
|
|
COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
elif [[ $cword -eq 2 ]]; then
|
|
|
|
case $cmd in
|
|
|
|
subvolume)
|
|
|
|
opts="$commands_subvolume"
|
|
|
|
;;
|
|
|
|
filesystem)
|
|
|
|
opts="$commands_filesystem"
|
|
|
|
;;
|
|
|
|
balance)
|
|
|
|
opts="$commands_balance"
|
|
|
|
;;
|
|
|
|
device)
|
|
|
|
opts="$commands_device"
|
|
|
|
;;
|
|
|
|
scrub)
|
|
|
|
opts="$commands_scrub"
|
|
|
|
;;
|
|
|
|
check)
|
2018-08-13 14:02:43 +08:00
|
|
|
_filedir
|
2017-09-12 09:04:10 +08:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
rescue)
|
|
|
|
opts="$commands_rescue"
|
|
|
|
;;
|
|
|
|
restore)
|
2018-08-13 14:02:43 +08:00
|
|
|
_filedir
|
2015-02-03 00:49:41 +08:00
|
|
|
return 0
|
2017-09-12 09:04:10 +08:00
|
|
|
;;
|
|
|
|
inspect-internal)
|
|
|
|
opts="$commands_inspect_internal"
|
|
|
|
;;
|
|
|
|
property)
|
|
|
|
opts="$commands_property"
|
|
|
|
;;
|
|
|
|
send|receive)
|
|
|
|
_filedir -d
|
2015-02-03 00:49:41 +08:00
|
|
|
return 0
|
2017-09-12 09:04:10 +08:00
|
|
|
;;
|
|
|
|
quota)
|
|
|
|
opts="$commands_quota"
|
|
|
|
;;
|
|
|
|
qgroup)
|
|
|
|
opts="$commands_qgroup"
|
|
|
|
;;
|
|
|
|
replace)
|
|
|
|
opts="$commands_replace"
|
|
|
|
;;
|
|
|
|
help)
|
|
|
|
opts="--full"
|
|
|
|
;;
|
|
|
|
version)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
|
|
|
|
return 0
|
|
|
|
elif [[ $cword -eq 3 ]]; then
|
|
|
|
case $cmd in
|
|
|
|
filesystem)
|
2015-02-03 00:49:41 +08:00
|
|
|
case $prev in
|
|
|
|
defragment)
|
|
|
|
_filedir
|
|
|
|
return 0
|
|
|
|
;;
|
2017-09-11 13:22:43 +08:00
|
|
|
df|usage)
|
|
|
|
_btrfs_mnts
|
|
|
|
return 0
|
|
|
|
;;
|
2015-02-03 00:49:41 +08:00
|
|
|
label)
|
|
|
|
_btrfs_mnts
|
2018-08-13 14:02:43 +08:00
|
|
|
_filedir
|
2015-02-03 00:49:41 +08:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
2017-09-12 09:04:10 +08:00
|
|
|
;;
|
|
|
|
device|rescue)
|
2018-08-13 14:02:43 +08:00
|
|
|
_filedir
|
2017-09-12 09:04:10 +08:00
|
|
|
return 0
|
|
|
|
;;
|
2017-09-11 13:22:43 +08:00
|
|
|
inspect-internal)
|
|
|
|
case $prev in
|
|
|
|
min-dev-size)
|
|
|
|
_btrfs_mnts
|
|
|
|
return 0
|
|
|
|
;;
|
2018-08-13 14:02:44 +08:00
|
|
|
dump-tree|dump-super|rootid|inode-resolve)
|
2017-09-11 13:22:43 +08:00
|
|
|
_filedir
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
receive)
|
|
|
|
case $prev in
|
|
|
|
-f)
|
|
|
|
_filedir
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2017-09-12 09:04:10 +08:00
|
|
|
replace)
|
|
|
|
case $prev in
|
|
|
|
status|cancel)
|
2015-02-03 00:49:41 +08:00
|
|
|
_btrfs_mnts
|
2017-09-12 09:04:10 +08:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
start)
|
2018-08-13 14:02:43 +08:00
|
|
|
_filedir
|
2017-09-12 09:04:10 +08:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2017-09-11 13:22:43 +08:00
|
|
|
subvolume)
|
|
|
|
case $prev in
|
|
|
|
list)
|
|
|
|
_btrfs_mnts
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2017-09-12 09:04:10 +08:00
|
|
|
esac
|
|
|
|
fi
|
2015-02-03 00:49:41 +08:00
|
|
|
|
2017-09-12 09:04:10 +08:00
|
|
|
_filedir -d
|
|
|
|
return 0
|
2015-02-03 00:49:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
complete -F _btrfs btrfs
|