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+ if [[ ${COMPREPLY[i]} == $1 ]]; 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 -- -W ' "${cur%%,*}",{0..31}'
19+ ;;
20+ aacraid,* ,* ,* )
21+ _comp_compgen -- -W ' aacraid,{0..3},{0..7},{0..31}'
22+ ;;
23+ aacraid,* ,* )
24+ _comp_compgen -- -W ' aacraid,{0..3},{0..7},'
25+ compopt -o nospace
26+ ;;
27+ sssraid,* ,* )
28+ _comp_compgen -- -W ' sssraid,{0..3},{0..31}'
29+ ;;
30+ aacraid,* | sssraid,* )
31+ _comp_compgen -- -W ' "${cur%%,*}",{0..3},'
32+ compopt -o nospace
33+ ;;
34+ hpt,* /* /* )
35+ _comp_compgen -- -W ' hpt,{1..4}/{1..8}/{1..4}'
36+ ;;
37+ hpt,* /* )
38+ _comp_compgen -- -W ' hpt,{1..4}/{1..8}{,/}'
39+ compopt -o nospace
840 ;;
9- hpt* )
10- _comp_compgen -- -W ' hpt,{1..4}/{1..8} hpt,{1..4}/{1..8}/{1..5}'
41+ hpt,* )
42+ _comp_compgen -- -W ' hpt,{1..4}/'
43+ compopt -o nospace
44+ ;;
45+ jmb39x,* | jmb39x-q,* | jmb39x-q2,* | jms56x,* )
46+ _comp_compgen -- -W ' "${cur%%,*}",{0..4}'
1147 ;;
1248 * )
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
49+ _comp_compgen -- -W ' auto test ata scsi nvme{,\,}
50+ sat{,\,auto}{,\,12} usb{jmicron,prolific,sunplus}
51+ snt{asmedia,jmicron,realtek}{,/sat} 3ware, aacraid, areca,
52+ cciss, hpt, megaraid, sssraid, jmb39x{,-q,-q2}, jms56x,'
53+ _comp_cmd_smartctl__set_nospace_if_any ' *,'
2054 ;;
2155 esac
2256}
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- }
3157_comp_cmd_smartctl__drivedb ()
3258{
3359 local prefix=
@@ -38,13 +64,39 @@ _comp_cmd_smartctl__drivedb()
3864 _comp_compgen_filedir h && [[ $prefix ]] &&
3965 _comp_compgen -Rv COMPREPLY -- -P " $prefix " -W ' "${COMPREPLY[@]}"'
4066}
67+ _comp_cmd_smartctl__vendorattribute ()
68+ {
69+ local fmt
70+ case $cur in
71+ [1-9N],* |[1-9][0-9],* |1[0-9][0-9],* |2[0-4][0-9],* |25[0-5],* )
72+ fmt=' raw{8,16,48,56,64},hex{48,56,64},raw24/raw{24,32}'
73+ fmt+=' ,msec24hour32,{sec,min,halfmin}2hour,temp10x,tempminmax'
74+ _comp_compgen -- -W ' "${cur%%,*}",{' " $fmt " ' }{,\,,}'
75+ ;;
76+ [1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
77+ _comp_compgen -- -W ' {1..255},'
78+ ;;
79+ * )
80+ _comp_compgen -- -W ' N, help'
81+ ;;
82+ esac
83+ compopt -o nospace
84+ }
85+ _comp_cmd_smartctl__set ()
86+ {
87+ _comp_compgen -- -W ' aam,{,off} apm,{,off} dsn,{on,off}
88+ lookahead,{on,off} rcache,{on,off} security-freeze standby,{,off,now}
89+ wcache,{on,off} wcache-sct,{ata,on,off}{,\,p}
90+ wcreorder,{on,off}{,\,p} ' " $1 "
91+ _comp_cmd_smartctl__set_nospace_if_any ' *,'
92+ }
4193
4294_comp_cmd_smartctl ()
4395{
4496 local cur prev words cword was_split comp_args
4597 _comp_initialize -s -- " $@ " || return
4698
47- local noargopts=' !(-*|*[qdTbrnsoSlvFPBt ]*)'
99+ local noargopts=' !(-*|*[qdTbrnoSlvFPBtfgs ]*)'
48100 # shellcheck disable=SC2254
49101 case $prev in
50102 --quietmode | -${noargopts} q)
@@ -64,32 +116,34 @@ _comp_cmd_smartctl()
64116 return
65117 ;;
66118 --report | -${noargopts} r)
67- _comp_compgen -- -W ' ioctl ataioctl scsiioctl '
119+ _comp_compgen -- -W ' {,ata,scsi,nvme} ioctl{,\,2} '
68120 return
69121 ;;
70122 --nocheck | -${noargopts} n)
71- _comp_compgen -- -W ' never sleep standby idle'
123+ _comp_compgen -- -W ' never sleep{,\,} standby{,\,} idle{,\,}'
124+ _comp_cmd_smartctl__set_nospace_if_any ' *,'
72125 return
73126 ;;
74- --smart | --offlineauto | --saveauto | -${noargopts} [soS ])
127+ --smart | --offlineauto | --saveauto | -${noargopts} [oS ])
75128 _comp_compgen -- -W ' on off'
76129 return
77130 ;;
78131 --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'
132+ _comp_compgen -- -W ' background defects{,\,} devstat{,\,}
133+ directory{,\,g,\,s} envrep error farm genstats gplog, nvmelog,
134+ sasphy{,\,reset} sataphy{,\,reset} scterc{,\,,\,p,\,reset}
135+ scttemp{,sts,int\,,hist} selective selftest smartlog, ssd
136+ tapealert tapedevstat xerror{,\,,\,error}
137+ xselftest{,\,,\,selftest} zdevstat'
138+ _comp_cmd_smartctl__set_nospace_if_any ' *,'
82139 return
83140 ;;
84141 --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'
142+ _comp_cmd_smartctl__vendorattribute
89143 return
90144 ;;
91145 --firmwarebug | -${noargopts} F)
92- _comp_compgen -- -W ' none samsung samsung2 samsung3 swapid'
146+ _comp_compgen -- -W ' none nologdir samsung{,2,3} swapid xerrorlba '
93147 return
94148 ;;
95149 --presets | -${noargopts} P)
@@ -101,7 +155,26 @@ _comp_cmd_smartctl()
101155 return
102156 ;;
103157 --test | -${noargopts} t)
104- _comp_cmd_smartctl__test
158+ _comp_compgen -- -W ' afterselect,{on,off} conveyance force long
159+ offline pending, scttempint, select,{,redo,next} short vendor,'
160+ _comp_cmd_smartctl__set_nospace_if_any ' *,'
161+ return
162+ ;;
163+ --format | -${noargopts} f)
164+ _comp_compgen -- -W ' brief hex{,\,id,\,val} old'
165+ return
166+ ;;
167+ --get | -${noargopts} g)
168+ _comp_compgen -- -W ' aam all apm dsn lookahead rcache security
169+ wcache{,-sct} wcreorder'
170+ return
171+ ;;
172+ --set)
173+ _comp_cmd_smartctl__set ' '
174+ return
175+ ;;
176+ -${noargopts} s) # -s {on,off}: --smart {on,off}; -s OTHER: --set OTHER
177+ _comp_cmd_smartctl__set ' on off'
105178 return
106179 ;;
107180 esac
@@ -110,7 +183,7 @@ _comp_cmd_smartctl()
110183
111184 if [[ $cur == -* ]]; then
112185 _comp_compgen_help
113- [[ ${COMPREPLY-} == * = ]] && compopt -o nospace
186+ _comp_cmd_smartctl__set_nospace_if_any ' *= '
114187 else
115188 _comp_compgen -c " ${cur:-/ dev/ } " filedir
116189 fi
0 commit comments