1#compdef hexdump hd 2 3local -a args fmts optpar 4fmts=( 5 {--one-byte-octal,-b}'[one-byte octal display]' 6 {--one-byte-char,-c}'[one-byte character display]' 7 {--two-bytes-decimal,-d}'[two-byte decimal display]' 8 {--two-bytes-octal,-o}'[two-byte octal display]' 9 {--two-bytes-hex,-x}'[two-byte hexadecimal display]' 10 {--format=,-e+}'[specify format string to be used for displaying data]:format' 11 {--format-file=,-f+}'[specify file that contains format strings]:file:_files' 12) 13args=( 14 '(H -n --length)'{--length=,-n+}'[interpret only specified amount of input]:length (bytes)' 15 '(H -s --skip)'{--skip=,-s+}'[skip specified bytes at the beginning]:offset (bytes)' 16 '(H -v --no-squeezing)'{--no-squeezing,-v}'[output identical lines]' 17) 18 19[[ $service = hexdump ]] && fmts+=( {--canonical,-C}'[canonical hex+ASCII display]' ) 20 21if [[ $OSTYPE = linux* ]]; then 22 args+=( 23 '(-L --color)'{-L+,--color=}'[interpret color formatting specifiers colors are enabled by default]:mode' 24 + H 25 '(- *)'{-h,--help}'[display usage information]' 26 '(- *)'{-V,--version}'[display version information]' 27 ) 28else 29 # strip long options by taking every second element 30 print -v fmts -f '%2$s' -- "$fmts[@]" 31 print -v args -f '%2$s' -- "$args[@]" 32 optpar=( -A "-*" ) 33fi 34 35_arguments -s -S $optpar '*:file:_files' $args + '(formats)' '(H)'$^fmts 36