#compdef srm
# ------------------------------------------------------------------------------
# Description
# -----------
#
#  Completion script for srm.
#
#  It is based on the rm completion script from Zsh.
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
#  * Sorin Ionescu <sorin.ionescu@gmail.com>
#
# ------------------------------------------------------------------------------

local -a opts args
args=(
  '(-f --force)'{-f,--force}'[ignore nonexistent files, never prompt]'
  '(-r --interactive)'{-i,--interactive}'[prompt before any removal]'
  '(-r -R --recursive)'{-r,-R,--recursive}'[remove the contents of directories recursively]'
  '(-s --simple)'{-s,--simple}'[only overwrite with a single pass of random data]'
  '(-v --verbose)'{-v,--verbose}'[explain what is being done]'
  '(- *)--help[display help message and exit]'
  '(- *)--version[output version information and exit]'
  '*::files:->file'
)

if _pick_variant gnu=gnu unix --help; then
  args+=(
    '(-x --one-file-system)'{-x,--one-file-system}'[stay within filesystems of files given as arguments]'
    '(-P --openbsd)'{-P,--openbsd}'[overwrite the file 3 times (0xff, 0x00, 0xff)]'
    '(-D --dod)'{-D,--dod}'[overwrite the file with 7 US DoD compliant passes (0xF6, 0x00, 0xFF, random, 0x00, 0xFF, random)]'
    '(-E --doe)'{-E,--doe}'[overwrite the file with 3 US DoE compliant passes (random, random, DoE)]'
  )
else
  args+=(
    '(-m --medium)'{-m,--medium}'[overwrite the file with 7 US DoD compliant passes (0xF6, 0x00, 0xFF, random, 0x00, 0xFF, random)]'
    '(-z --zero)'{-z,--zero}'[after overwriting, zero blocks used by file]'
    '(-n --nounlink)'{-n,--nounlink}'[overwrite file, but do not rename or unlink it]' 
  )
fi

local curcontext=$curcontext state line ret=1
local -A opt_args

_arguments -s -S -C $opts \
  $args && ret=0

case $state in
  (file)
    local -a ignored
    ignored=()
    ((CURRENT > 1)) &&
      ignored+=(${line[1,CURRENT-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
    ((CURRENT < $#line)) &&
      ignored+=(${line[CURRENT+1,-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
    _files -F ignored && ret=0
    ;;
esac

return $ret
