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_any ()
5+ {
6+ local i
7+ for i in " ${! COMPREPLY[@]} " ; do
8+ # shellcheck disable=SC2053
9+ if [[ ${COMPREPLY[i]} == $1 ]]; then
10+ compopt -o nospace
11+ break
12+ fi
13+ done
14+ }
315_comp_cmd_smartctl__device ()
416{
517 case $cur in
6- areca* | 3ware* | megaraid* | cciss* )
7- _comp_compgen -- -W ' ${cur%%,*},{0..31}'
18+ 3ware,* | areca,* | cciss,* | megaraid,* )
19+ _comp_compgen -- -W ' "${cur%%,*}",{0..31}'
20+ ;;
21+ aacraid,* ,* ,* )
22+ _comp_compgen -- -W ' aacraid,{0..3},{0..7},{0..31}'
23+ ;;
24+ aacraid,* ,* )
25+ _comp_compgen -- -W ' aacraid,{0..3},{0..7},'
26+ compopt -o nospace
27+ ;;
28+ sssraid,* ,* )
29+ _comp_compgen -- -W ' sssraid,{0..3},{0..31}'
30+ ;;
31+ aacraid,* | sssraid,* )
32+ _comp_compgen -- -W ' "${cur%%,*}",{0..3},'
33+ compopt -o nospace
34+ ;;
35+ hpt,* /* /* )
36+ _comp_compgen -- -W ' hpt,{1..4}/{1..8}/{1..4}'
37+ ;;
38+ hpt,* /* )
39+ _comp_compgen -- -W ' hpt,{1..4}/{1..8}{,/}'
40+ compopt -o nospace
841 ;;
9- hpt* )
10- _comp_compgen -- -W ' hpt,{1..4}/{1..8} hpt,{1..4}/{1..8}/{1..5}'
42+ hpt,* )
43+ _comp_compgen -- -W ' hpt,{1..4}/'
44+ compopt -o nospace
45+ ;;
46+ jmb39x,* | jmb39x-q,* | jmb39x-q2,* | jms56x,* )
47+ _comp_compgen -- -W ' "${cur%%,*}",{0..4}'
1148 ;;
1249 * )
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
50+ _comp_compgen -- -W ' auto test ata scsi nvme{,\,}
51+ sat{,\,auto}{,\,12} usb{jmicron,prolific,sunplus}
52+ snt{asmedia,jmicron,realtek}{,/sat} 3ware, aacraid, areca,
53+ cciss, hpt, megaraid, sssraid, jmb39x{,-q,-q2}, jms56x,'
54+ _comp_cmd_smartctl__set_nospace_if_any ' *,'
2055 ;;
2156 esac
2257}
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- }
3158_comp_cmd_smartctl__drivedb ()
3259{
3360 local prefix=
@@ -38,13 +65,39 @@ _comp_cmd_smartctl__drivedb()
3865 _comp_compgen_filedir h && [[ $prefix ]] &&
3966 _comp_compgen -Rv COMPREPLY -- -P " $prefix " -W ' "${COMPREPLY[@]}"'
4067}
68+ _comp_cmd_smartctl__vendorattribute ()
69+ {
70+ local fmt
71+ case $cur in
72+ [1-9N],* | [1-9][0-9],* | 1[0-9][0-9],* | 2[0-4][0-9],* | 25[0-5],* )
73+ fmt=' raw{8,16,48,56,64},hex{48,56,64},raw24/raw{24,32}'
74+ fmt+=' ,msec24hour32,{sec,min,halfmin}2hour,temp10x,tempminmax'
75+ _comp_compgen -- -W ' "${cur%%,*}",{' " $fmt " ' }{,\,,}'
76+ ;;
77+ [1-9] | [1-9][0-9] | 1[0-9][0-9] | 2[0-4][0-9] | 25[0-5])
78+ _comp_compgen -- -W ' {1..255},'
79+ ;;
80+ * )
81+ _comp_compgen -- -W ' N, help'
82+ ;;
83+ esac
84+ compopt -o nospace
85+ }
86+ _comp_cmd_smartctl__set ()
87+ {
88+ _comp_compgen -- -W ' aam,{,off} apm,{,off} dsn,{on,off}
89+ lookahead,{on,off} rcache,{on,off} security-freeze standby,{,off,now}
90+ wcache,{on,off} wcache-sct,{ata,on,off}{,\,p}
91+ wcreorder,{on,off}{,\,p} ' " $1 "
92+ _comp_cmd_smartctl__set_nospace_if_any ' *,'
93+ }
4194
4295_comp_cmd_smartctl ()
4396{
4497 local cur prev words cword was_split comp_args
4598 _comp_initialize -s -- " $@ " || return
4699
47- local noargopts=' !(-*|*[qdTbrnsoSlvFPBt ]*)'
100+ local noargopts=' !(-*|*[qdTbrnoSlvFPBtfgs ]*)'
48101 # shellcheck disable=SC2254
49102 case $prev in
50103 --quietmode | -${noargopts} q)
@@ -64,32 +117,34 @@ _comp_cmd_smartctl()
64117 return
65118 ;;
66119 --report | -${noargopts} r)
67- _comp_compgen -- -W ' ioctl ataioctl scsiioctl '
120+ _comp_compgen -- -W ' {,ata,scsi,nvme} ioctl{,\,2} '
68121 return
69122 ;;
70123 --nocheck | -${noargopts} n)
71- _comp_compgen -- -W ' never sleep standby idle'
124+ _comp_compgen -- -W ' never sleep{,\,} standby{,\,} idle{,\,}'
125+ _comp_cmd_smartctl__set_nospace_if_any ' *,'
72126 return
73127 ;;
74- --smart | --offlineauto | --saveauto | -${noargopts} [soS ])
128+ --smart | --offlineauto | --saveauto | -${noargopts} [oS ])
75129 _comp_compgen -- -W ' on off'
76130 return
77131 ;;
78132 --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'
133+ _comp_compgen -- -W ' background defects{,\,} devstat{,\,}
134+ directory{,\,g,\,s} envrep error farm genstats gplog, nvmelog,
135+ sasphy{,\,reset} sataphy{,\,reset} scterc{,\,,\,p,\,reset}
136+ scttemp{,sts,int\,,hist} selective selftest smartlog, ssd
137+ tapealert tapedevstat xerror{,\,,\,error}
138+ xselftest{,\,,\,selftest} zdevstat'
139+ _comp_cmd_smartctl__set_nospace_if_any ' *,'
82140 return
83141 ;;
84142 --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'
143+ _comp_cmd_smartctl__vendorattribute
89144 return
90145 ;;
91146 --firmwarebug | -${noargopts} F)
92- _comp_compgen -- -W ' none samsung samsung2 samsung3 swapid'
147+ _comp_compgen -- -W ' none nologdir samsung{,2,3} swapid xerrorlba '
93148 return
94149 ;;
95150 --presets | -${noargopts} P)
@@ -101,7 +156,26 @@ _comp_cmd_smartctl()
101156 return
102157 ;;
103158 --test | -${noargopts} t)
104- _comp_cmd_smartctl__test
159+ _comp_compgen -- -W ' afterselect,{on,off} conveyance force long
160+ offline pending, scttempint, select,{,redo,next} short vendor,'
161+ _comp_cmd_smartctl__set_nospace_if_any ' *,'
162+ return
163+ ;;
164+ --format | -${noargopts} f)
165+ _comp_compgen -- -W ' brief hex{,\,id,\,val} old'
166+ return
167+ ;;
168+ --get | -${noargopts} g)
169+ _comp_compgen -- -W ' aam all apm dsn lookahead rcache security
170+ wcache{,-sct} wcreorder'
171+ return
172+ ;;
173+ --set)
174+ _comp_cmd_smartctl__set ' '
175+ return
176+ ;;
177+ -${noargopts} s) # -s {on,off}: --smart {on,off}; -s OTHER: --set OTHER
178+ _comp_cmd_smartctl__set ' on off'
105179 return
106180 ;;
107181 esac
@@ -110,7 +184,7 @@ _comp_cmd_smartctl()
110184
111185 if [[ $cur == -* ]]; then
112186 _comp_compgen_help
113- [[ ${COMPREPLY-} == * = ]] && compopt -o nospace
187+ _comp_cmd_smartctl__set_nospace_if_any ' *= '
114188 else
115189 _comp_compgen -c " ${cur:-/ dev/ } " filedir
116190 fi
0 commit comments