aboutsummaryrefslogtreecommitdiffstats
path: root/src/_srm
blob: f997c9f6826966395518f59475b0e255e37b26d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#compdef srm
# ------------------------------------------------------------------------------
# Copyright (c) 2016 Github zsh-users - https://github.com/zsh-users
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# ------------------------------------------------------------------------------
# Description
# -----------
#
#  Completion script for srm.
#
#  It is based on the rm completion script from Zsh.
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
#  * Sorin Ionescu <sorin.ionescu@gmail.com>
#
# ------------------------------------------------------------------------------

local -a args
local variant

args=(
  '*::files:->file'
)

_pick_variant -r variant gnu=gnu thc=THC unix --help

if [[ $variant == "thc" ]]; then
  args+=(
    '-d[ignore the two special dot files . and .. on the commandline]'
    '-f[fast (and insecure mode)]'
    '*-l[lessens the security. -l for a second time lessons the security even more]'
    '-r[recursive mode]'
    '-v[verbose mode]'
    '-z[wipes the last write with zeros instead of random data]'
  )
else
  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]'
  )

  if [[ $variant == "gnu" ]]; 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
fi

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

_arguments -s -S -C $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

# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et