summary refs log tree commit diff
path: root/Completion/Unix/Command/_rm
blob: 6d728b157f8580bfbb5cd6bcb4a31f7c3b3ef050 (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
#compdef rm grm zf_rm

declare -a opts args
args=(
  '(-f --force)'{-f,--force}'[ignore nonexistent files, never prompt]'
  '(-I --interactive)-i[prompt before every removal]'
  '(-r -R --recursive)'{-r,-R,--recursive}'[remove directories and their contents recursively]'
  '*::files:->file'
)
if _pick_variant gnu=gnu unix --help; then
  opts+=(-S)
  args+=(
    '(-i --interactive)-I[prompt when removing many files]'
    '(-i -I)--interactive=-[prompt under given condition (defaulting to always)]::when:((once\:"prompt when removing many files"
                                                                                         always\:"prompt before every removal"))'
    '--one-file-system[stay within filesystems of files given as arguments]'
    '(                   --preserve-root)--no-preserve-root[do not treat / specially]'
    '(--no-preserve-root                )--preserve-root[do not remove / (default)]'
    '(-d --dir)'{-d,--dir}'[remove directories as well]'
    '(-v --verbose)'{-v,--verbose}'[explain what is being done]'
    '(- *)--help[display help message and exit]'
    '(- *)--version[output version information and exit]'
  )
else
  args=(${args:#*)--*\[*})
  case $OSTYPE in
    dragonfly*|freebsd*|netbsd*|openbsd*)
      args+=(
        '-d[remove directories as well]'
        '-P[overwrite files before deleting them]'
      )
    ;|
    dragonfly*|freebsd*|netbsd*)
      args+=(
        '-v[explain what is being done]'
        '-W[attempt to undelete named files]'
        "-x[don't cross file systems when removing a hierarchy]"
      )
    ;|
    dragonfly*|freebsd*)
      args+=(
        '(-i)-I[prompt when removing many files]'
      )
    ;;
  esac
fi

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

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

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

return $ret