Skip to content

Commit 3375ba9

Browse files
committed
feat(smartctl): update for smartmontools 7.5
1 parent 360b87d commit 3375ba9

File tree

1 file changed

+119
-33
lines changed

1 file changed

+119
-33
lines changed

completions/smartctl

Lines changed: 119 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,67 @@
11
# bash completion for smartctl(8) -*- shell-script -*-
2+
# Updated for smartmontools 7.5 (released 2025-04-30)
23

4+
_comp_cmd_smartctl__set_nospace_if_incomplete()
5+
{
6+
local i
7+
for i in "${!COMPREPLY[@]}"; do
8+
if [[ ${COMPREPLY[i]} == *[,=] ]]; then
9+
compopt -o nospace
10+
break
11+
fi
12+
done
13+
}
314
_comp_cmd_smartctl__device()
415
{
516
case $cur in
6-
areca* | 3ware* | megaraid* | cciss*)
7-
_comp_compgen -- -W '${cur%%,*},{0..31}'
17+
3ware,* | areca,* | cciss,* | megaraid,*)
18+
_comp_compgen -P "${cur%%,*}," -- -W '{0..31}'
19+
;;
20+
aacraid,*,*,*,*) ;;
21+
aacraid,[0-7],[0-7],*)
22+
_comp_compgen -P "${cur%,*}," -- -W '{0..31}'
23+
;;
24+
aacraid,*,*,*) ;;
25+
aacraid,[0-7],*)
26+
_comp_compgen -P "${cur%,*}," -- -W '{0..7},'
27+
compopt -o nospace
28+
;;
29+
aacraid,*)
30+
_comp_compgen -P "aacraid," -- -W '{0..7},'
31+
compopt -o nospace
32+
;;
33+
hpt,*/*/*/*) ;;
34+
hpt,[1-4]/[1-8]/*)
35+
_comp_compgen -P "${cur%/*}/" -- -W '{1..8}'
36+
;;
37+
hpt,[1-4]/*)
38+
_comp_compgen -P "${cur%%/*}/" -- -W '{1..8}{,/}'
39+
compopt -o nospace
40+
;;
41+
hpt,*)
42+
_comp_compgen -P "hpt," -- -W '{1..4}/'
43+
compopt -o nospace
844
;;
9-
hpt*)
10-
_comp_compgen -- -W 'hpt,{1..4}/{1..8} hpt,{1..4}/{1..8}/{1..5}'
45+
jmb39x,* | jmb39x-q,* | jmb39x-q2,* | jms56x,*)
46+
_comp_compgen -P "${cur%%,*}," -- -W '{0..4}'
47+
;;
48+
sssraid,*,*,*) ;;
49+
sssraid,[0-7],*)
50+
_comp_compgen -P "${cur%,*}," -- -W '{0..31}'
51+
;;
52+
sssraid,*)
53+
_comp_compgen -P "sssraid," -- -W '{0..7},'
54+
compopt -o nospace
1155
;;
1256
*)
13-
_comp_compgen -- -W 'ata scsi sat usbcypress usbjmicron usbsunplus
14-
marvell areca 3ware hpt megaraid cciss auto test'
15-
case "${COMPREPLY[@]}" in
16-
areca | 3ware | hpt | megaraid | cciss)
17-
compopt -o nospace
18-
;;
19-
esac
57+
_comp_compgen -- -W 'auto test ata scsi nvme{,\,}
58+
sat{,\,auto}{,\,12} usb{jmicron,prolific,sunplus}
59+
snt{asmedia,jmicron,realtek}{,/sat} 3ware, aacraid, areca,
60+
cciss, hpt, megaraid, sssraid, jmb39x{,-q,-q2}, jms56x,'
61+
_comp_cmd_smartctl__set_nospace_if_incomplete
2062
;;
2163
esac
2264
}
23-
_comp_cmd_smartctl__test()
24-
{
25-
[[ $cur == @(pending|scttempint|vendor), ]] && return
26-
_comp_compgen -- -W 'offline short long conveyance select, select,redo
27-
select,next afterselect,on afterselect,off pending, scttempint,
28-
vendor,'
29-
[[ ${COMPREPLY-} == *, ]] && compopt -o nospace
30-
}
3165
_comp_cmd_smartctl__drivedb()
3266
{
3367
local prefix=
@@ -38,13 +72,44 @@ _comp_cmd_smartctl__drivedb()
3872
_comp_compgen_filedir h && [[ $prefix ]] &&
3973
_comp_compgen -Rv COMPREPLY -- -P "$prefix" -W '"${COMPREPLY[@]}"'
4074
}
75+
_comp_cmd_smartctl__vendorattribute()
76+
{
77+
case $cur in
78+
[1-9N],* | [1-9][0-9],* | 1[0-9][0-9],* | 2[0-4][0-9],* | 25[0-5],*)
79+
# TODO: add 'raw16(raw16)', 'raw16(avg16)' and 'raw24(raw8)'.
80+
# Excluded for now because 'compopt -o fullquote' (Bash >= 5.3)
81+
# or similar bash_completion functionality would be required.
82+
_comp_compgen -P "${cur%%,*}," -- -W 'raw{8,16,48,56,64}
83+
hex{48,56,64} raw24/raw{24,32} msec24hour32
84+
{sec,min,halfmin}2hour temp{10x,minmax}'
85+
if ((${#COMPREPLY[@]} == 1)); then
86+
_comp_compgen -R -- -W '"$COMPREPLY"{,\,,:}'
87+
fi
88+
;;
89+
[1-9] | [1-9][0-9] | 1[0-9][0-9] | 2[0-4][0-9] | 25[0-5])
90+
_comp_compgen -- -W '{1..255},'
91+
;;
92+
*)
93+
_comp_compgen -- -W 'N, help'
94+
;;
95+
esac
96+
compopt -o nospace
97+
}
98+
_comp_cmd_smartctl__set()
99+
{
100+
_comp_compgen -- -W 'aam,{,off} apm,{,off} dsn,{on,off}
101+
lookahead,{on,off} rcache,{on,off} security-freeze standby,{,off,now}
102+
wcache,{on,off} wcache-sct,{ata,on,off}{,\,p}
103+
wcreorder,{on,off}{,\,p} '"$1"
104+
_comp_cmd_smartctl__set_nospace_if_incomplete
105+
}
41106

42107
_comp_cmd_smartctl()
43108
{
44109
local cur prev words cword was_split comp_args
45110
_comp_initialize -s -- "$@" || return
46111

47-
local noargopts='!(-*|*[qdTbrnsoSlvFPBt]*)'
112+
local noargopts='!(-*|*[qdTbrnoSlvFPBtfgs]*)'
48113
# shellcheck disable=SC2254
49114
case $prev in
50115
--quietmode | -${noargopts}q)
@@ -64,32 +129,34 @@ _comp_cmd_smartctl()
64129
return
65130
;;
66131
--report | -${noargopts}r)
67-
_comp_compgen -- -W 'ioctl ataioctl scsiioctl'
132+
_comp_compgen -- -W '{,ata,scsi,nvme}ioctl{,\,2}'
68133
return
69134
;;
70135
--nocheck | -${noargopts}n)
71-
_comp_compgen -- -W 'never sleep standby idle'
136+
_comp_compgen -- -W 'never sleep{,\,} standby{,\,} idle{,\,}'
137+
_comp_cmd_smartctl__set_nospace_if_incomplete
72138
return
73139
;;
74-
--smart | --offlineauto | --saveauto | -${noargopts}[soS])
140+
--smart | --offlineauto | --saveauto | -${noargopts}[oS])
75141
_comp_compgen -- -W 'on off'
76142
return
77143
;;
78144
--log | -${noargopts}l)
79-
_comp_compgen -- -W 'error selftest selective directory background
80-
sasphy sasphy,reset sataphy sataphy,reset scttemp scttempsts
81-
scttemphist scterc gplog smartlog xerror xselftest'
145+
_comp_compgen -- -W 'background defects{,\,} devstat{,\,}
146+
directory{,\,g,\,s} envrep error farm genstats gplog, nvmelog,
147+
sasphy{,\,reset} sataphy{,\,reset} scterc{,\,,\,p,\,reset}
148+
scttemp{,sts,int\,,hist} selective selftest smartlog, ssd
149+
tapealert tapedevstat xerror{,\,,\,error}
150+
xselftest{,\,,\,selftest} zdevstat'
151+
_comp_cmd_smartctl__set_nospace_if_incomplete
82152
return
83153
;;
84154
--vendorattribute | -${noargopts}v)
85-
_comp_compgen -- -W 'help 9,minutes 9,seconds 9,halfminutes 9,temp
86-
192,emergencyretractcyclect 193,loadunload 194,10xCelsius
87-
194,unknown 198,offlinescanuncsectorct 200,writeerrorcount
88-
201,detectedtacount 220,temp'
155+
_comp_cmd_smartctl__vendorattribute
89156
return
90157
;;
91158
--firmwarebug | -${noargopts}F)
92-
_comp_compgen -- -W 'none samsung samsung2 samsung3 swapid'
159+
_comp_compgen -- -W 'none nologdir samsung{,2,3} swapid xerrorlba'
93160
return
94161
;;
95162
--presets | -${noargopts}P)
@@ -101,7 +168,26 @@ _comp_cmd_smartctl()
101168
return
102169
;;
103170
--test | -${noargopts}t)
104-
_comp_cmd_smartctl__test
171+
_comp_compgen -- -W 'afterselect,{on,off} conveyance force long
172+
offline pending, scttempint, select,{,redo,next} short vendor,'
173+
_comp_cmd_smartctl__set_nospace_if_incomplete
174+
return
175+
;;
176+
--format | -${noargopts}f)
177+
_comp_compgen -- -W 'brief hex{,\,id,\,val} old'
178+
return
179+
;;
180+
--get | -${noargopts}g)
181+
_comp_compgen -- -W 'aam all apm dsn lookahead rcache security
182+
wcache{,-sct} wcreorder'
183+
return
184+
;;
185+
--set)
186+
_comp_cmd_smartctl__set ''
187+
return
188+
;;
189+
-${noargopts}s) # -s {on,off}: --smart {on,off}; -s OTHER: --set OTHER
190+
_comp_cmd_smartctl__set 'on off'
105191
return
106192
;;
107193
esac
@@ -110,7 +196,7 @@ _comp_cmd_smartctl()
110196

111197
if [[ $cur == -* ]]; then
112198
_comp_compgen_help
113-
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
199+
_comp_cmd_smartctl__set_nospace_if_incomplete
114200
else
115201
_comp_compgen -c "${cur:-/dev/}" filedir
116202
fi

0 commit comments

Comments
 (0)