blob: cf0a73ac2332177381bb3a623d0a11de61296f26 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# *** Public Domain ***
#
# Uncomment if do not have zfs bash completion:
#__zfs_get_editable_properties()
#{
# zfs get 2>&1 | awk '$2 == "YES" {printf("%s=\n", $1)}'
#}
#
#__zpool_list_pools()
#{
# zpool list -H -o name
#}
__beadm_be_list () {
beadm list -H 2>/dev/null | nawk -F';' '{print $1}'
}
__beadm_be_at_list () {
beadm list -H 2>/dev/null | nawk -F';' '{print $1"@"}'
}
# List of mounted BE and mount points (for unmount command)
__beadm_unmount_list () {
beadm list -H 2>/dev/null | nawk -F';' '$4 != "/" && $4 != "" {print $1" "$4}'
}
__beadm_nonactive_list () {
beadm list -H 2>/dev/null | nawk -F';' '$3 !~ "N" {print $1}'
}
__beadm_nonactive_reboot_list () {
beadm list -H 2>/dev/null | nawk -F';' '$3 !~ "R" {print $1}'
}
__beadm_snapshot_list () {
beadm list -s -H 2>/dev/null | nawk -F';' '{print $2}'
}
_beadm () {
local cur prev opts line
COMPREPLY=()
# Allow @ (at-sign) for snapshots:
shopt -u hostcomplete
cur=${COMP_WORDS[COMP_CWORD]}
prev="${COMP_WORDS[COMP_CWORD-1]}"
line="${COMP_LINE}"
cmd="${COMP_WORDS[1]}"
if [[ ${COMP_CWORD} -eq 1 ]]; then
COMPREPLY=( $(compgen -W "create destroy list mount \
unmount rename activate rollback" -- $cur) )
return
fi
case "$cmd" in
create)
case "$prev" in
-e)
COMPREPLY=( $(compgen -W "$(__beadm_nonactive_list) $(__beadm_snapshot_list)" -- $cur) )
;;
-p)
COMPREPLY=( $(compgen -W "$(__zpool_list_pools)" -- $cur) )
;;
-o)
COMPREPLY=( $(compgen -W "$(__zfs_get_editable_properties)" -- $cur) )
;;
*)
COMPREPLY=( $(compgen -W "-a -d -e -o -p -v $(__beadm_be_at_list)" -- $cur) )
if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} != -* ]]; then
compopt -o nospace
fi
;;
esac
;;
destroy)
case "$line" in
*"-s "*)
COMPREPLY=( $(compgen -W "$(__beadm_nonactive_list) -f -F -v" -- $cur) )
;;
*)
COMPREPLY=( $(compgen -W "$(__beadm_snapshot_list) $(__beadm_nonactive_list) -f -s -F -v" -- $cur) )
;;
esac
;;
list)
case "$line" in
*"-a "*)
COMPREPLY=( $(compgen -W "$(__beadm_be_list) -H -v" -- $cur) )
;;
*"-d "*)
COMPREPLY=( $(compgen -W "$(__beadm_be_list) -s -H -v" -- $cur) )
;;
*"-s "*)
COMPREPLY=( $(compgen -W "$(__beadm_be_list) -d -H -v" -- $cur) )
;;
*)
COMPREPLY=( $(compgen -W "$(__beadm_be_list) -a -d -s -H -v" -- $cur) )
;;
esac
;;
mount)
case "$prev" in
mount)
COMPREPLY=( $(compgen -W "$(__beadm_be_list) -v" -- $cur) )
;;
-v)
COMPREPLY=( $(compgen -W "$(__beadm_be_list)" -- $cur) )
;;
*)
_cd
;;
esac
;;
unmount)
COMPREPLY=( $(compgen -W "$(__beadm_unmount_list) -v -f" -- $cur) )
;;
rollback)
COMPREPLY=( $(compgen -W "$(__beadm_snapshot_list) -v" -- $cur) )
;;
activate)
COMPREPLY=( $(compgen -W "$(__beadm_nonactive_reboot_list) -v" -- $cur) )
;;
esac
}
complete -F _beadm beadm
|