9af6f3504e
Cuts ~10% from bash completion load time on two different systems I just tested.
191 lines
5.1 KiB
Bash
191 lines
5.1 KiB
Bash
# bash completion for smartctl(8)
|
|
|
|
have smartctl || return
|
|
|
|
_smartctl_quietmode()
|
|
{
|
|
COMPREPLY=( $( compgen -W 'errorsonly silent noserial' -- "$cur" ) )
|
|
}
|
|
_smartctl_device()
|
|
{
|
|
case $cur in
|
|
areca*|3ware*|megaraid*|cciss*)
|
|
local i mycur="${cur%%,*}"
|
|
for (( i=0; i <= 31; i++ )) ; do
|
|
COMPREPLY=( "${COMPREPLY[@]}" "$mycur,$i" )
|
|
done
|
|
COMPREPLY=( $( compgen -W '"${COMPREPLY[@]}"' -- "$cur" ) )
|
|
;;
|
|
hpt*)
|
|
local l m n
|
|
for (( l=1; l <= 4; l++ )) ; do
|
|
for (( m=1; m <= 8; m++ )) ; do
|
|
COMPREPLY=( "${COMPREPLY[@]}" hpt,$l/$m )
|
|
for (( n=1; n <= 5; n++ )) ; do
|
|
COMPREPLY=( "${COMPREPLY[@]}" hpt,$l/$m/$n )
|
|
done
|
|
done
|
|
done
|
|
COMPREPLY=( $( compgen -W '"${COMPREPLY[@]}"' -- "$cur" ) )
|
|
;;
|
|
*)
|
|
COMPREPLY=( $( compgen -W "ata scsi sat usbcypress usbjmicron
|
|
usbsunplus marvell areca 3ware hpt megaraid cciss auto test" \
|
|
-- "$cur" ) )
|
|
case "${COMPREPLY[@]}" in
|
|
areca|3ware|hpt|megaraid|cciss)
|
|
type compopt &>/dev/null && compopt -o nospace
|
|
;;
|
|
esac
|
|
;;
|
|
esac
|
|
}
|
|
_smartctl_tolerance()
|
|
{
|
|
COMPREPLY=( $( compgen -W 'normal conservative permissive \
|
|
verypermissive' -- "$cur" ) )
|
|
}
|
|
_smartctl_badsum()
|
|
{
|
|
COMPREPLY=( $( compgen -W 'warn exit ignore' -- "$cur" ) )
|
|
}
|
|
_smartctl_report()
|
|
{
|
|
COMPREPLY=( $( compgen -W 'ioctl ataioctl scsiioctl' -- "$cur" ) )
|
|
}
|
|
_smartctl_powermode()
|
|
{
|
|
COMPREPLY=( $( compgen -W 'never sleep standby idle' -- "$cur" ) )
|
|
}
|
|
_smartctl_feature()
|
|
{
|
|
COMPREPLY=( $( compgen -W 'on off' -- "$cur" ) )
|
|
}
|
|
_smartctl_log()
|
|
{
|
|
COMPREPLY=( $( compgen -W 'error selftest selective directory background
|
|
sasphy sasphy,reset sataphy sataphy,reset scttemp scttempsts
|
|
scttemphist scterc gplog smartlog xerror xselftest' -- "$cur" ) )
|
|
}
|
|
_smartctl_vendorattribute()
|
|
{
|
|
COMPREPLY=( $( compgen -W 'help 9,minutes 9,seconds 9,halfminutes \
|
|
9,temp 192,emergencyretractcyclect 193,loadunload \
|
|
194,10xCelsius 194,unknown 198,offlinescanuncsectorct \
|
|
200,writeerrorcount 201,detectedtacount 220,temp' -- "$cur" ) )
|
|
}
|
|
_smartctl_firmwarebug()
|
|
{
|
|
COMPREPLY=( $( compgen -W 'none samsung samsung2 samsung3 swapid' \
|
|
-- "$cur" ) )
|
|
}
|
|
_smartctl_presets()
|
|
{
|
|
COMPREPLY=( $( compgen -W 'use ignore show showall' -- "$cur" ) )
|
|
}
|
|
_smartctl_test()
|
|
{
|
|
[[ $cur == @(pending|scttempint|vendor), ]] && return 0
|
|
COMPREPLY=( $( compgen -W 'offline short long conveyance select,
|
|
select,redo select,next afterselect,on afterselect,off pending,
|
|
scttempint, vendor,' -- "$cur" ) )
|
|
[[ ${#COMPREPLY[@]} -eq 1 && "${COMPREPLY[@]}" == *, ]] && \
|
|
type compopt &>/dev/null && compopt -o nospace
|
|
}
|
|
_smartctl_drivedb()
|
|
{
|
|
local prefix=
|
|
if [[ $cur == +* ]] ; then
|
|
prefix=+
|
|
cur="${cur#+}"
|
|
fi
|
|
_filedir h
|
|
[[ -n $prefix ]] && COMPREPLY=( "${COMPREPLY[@]/#/$prefix}" )
|
|
}
|
|
|
|
_smartctl()
|
|
{
|
|
local cur prev split=false
|
|
|
|
COMPREPLY=()
|
|
_get_comp_words_by_ref cur prev
|
|
|
|
_split_longopt && split=true
|
|
|
|
case $prev in
|
|
-q|--quietmode)
|
|
_smartctl_quietmode
|
|
;;
|
|
-d|--device)
|
|
_smartctl_device
|
|
return 0
|
|
;;
|
|
-t|--tolerance)
|
|
_smartctl_tolerance
|
|
return 0
|
|
;;
|
|
-b|--badsum)
|
|
_smartctl_badsum
|
|
return 0
|
|
;;
|
|
-r|--report)
|
|
_smartctl_report
|
|
return 0
|
|
;;
|
|
-n|--nocheck)
|
|
_smartctl_powermode
|
|
return 0
|
|
;;
|
|
-s|--smart|-o|--offlineauto|-S|--saveauto)
|
|
_smartctl_feature
|
|
return 0
|
|
;;
|
|
-l|--log)
|
|
_smartctl_log
|
|
return 0
|
|
;;
|
|
-v|--vendorattribute)
|
|
_smartctl_vendorattribute
|
|
return 0
|
|
;;
|
|
-F|--firmwarebug)
|
|
_smartctl_firmwarebug
|
|
return 0
|
|
;;
|
|
-P|--presets)
|
|
_smartctl_presets
|
|
return 0
|
|
;;
|
|
-B|--drivedb)
|
|
_smartctl_drivedb
|
|
return 0
|
|
;;
|
|
-t|--test)
|
|
_smartctl_test
|
|
return 0
|
|
;;
|
|
esac
|
|
|
|
$split && return 0
|
|
|
|
if [[ "$cur" == -* ]]; then
|
|
COMPREPLY=( $( compgen -W '--help --version --info --all --xall
|
|
--scan --scan-open --quietmode --device --tolerance --badsum
|
|
--report --nocheck --smart --offlineauto --saveauto --health
|
|
--capabilities --attributes --log --vendorattribute --firmwarebug
|
|
--presets --drivedb --test --captive --abort' -- "$cur" ) )
|
|
else
|
|
cur=${cur:=/dev/}
|
|
_filedir
|
|
fi
|
|
} &&
|
|
complete -F _smartctl smartctl
|
|
|
|
# Local variables:
|
|
# mode: shell-script
|
|
# sh-basic-offset: 4
|
|
# sh-indent-comment: t
|
|
# indent-tabs-mode: nil
|
|
# End:
|
|
# ex: ts=4 sw=4 et filetype=sh
|