summary refs log tree commit diff
path: root/Completion/Unix/Command/_perl
blob: 64163c3a18369d58423da8dc52a8ecd9bbfe57c3 (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
#compdef perl
#
# zsh completion code for the Perl interpreter
# Adam Spiers <adam@spiers.net>
#

_perl () {
  _arguments -s \
    '-0-:input record separator in octal (\0, if no argument): ' \
    '-a[autosplit mode with -n or -p (splits $_ into @F)]' \
    "-c[check syntax only (runs BEGIN and END blocks)]" \
    '-d[run scripts under debugger]' \
    '-d\:-[run under control of a debugging/tracing module]:debugging/tracing module:_perl_modules' \
    '-D-:set debugging flags (argument is a bit mask or flags): ' \
    "*-e+:one line of script. Several -e's allowed. Omit [programfile]." \
    "-F-:split() pattern for autosplit (-a). The //'s are optional.: " \
    '-h[list help summary]' \
    '-i-[edit <> files in place (make backup if extension supplied)]:backup file extension: ' \
    '*-I-[specify @INC/#include directory (may be used more than once)]:include path:_files -/' \
    '-l-[enable line ending processing, specifies line terminator]:output record separator in octal: ' \
    \*{-m,-M}"-[module.. executes \`use/no module...' before executing your script.]:module:_perl_m_opt" \
    "-n[assume 'while (<>) { ... }' loop around your script]" \
    "-p[assume loop like -n but print line also like sed]" \
    "-P[run script through C preprocessor before compilation]" \
    "-s[enable some switch parsing for switches after script name]" \
    "-S[look for the script using PATH environment variable]" \
    "-T[turn on tainting checks]" \
    "-u[dump core after parsing script]" \
    "-U[allow unsafe operations]" \
    "-v[print version number, patchlevel plus VERY IMPORTANT perl info]" \
    "-V-[print perl configuration information]:configuration keys:_perl_config_vars" \
    '-w[TURN WARNINGS ON FOR COMPILATION OF YOUR SCRIPT. Recommended.]' \
    '-x-[strip off text before #!perl line and perhaps cd to directory]:directory to cd to:_files -/' \
    '*:Perl script:_files -/ -g \*.p\[ml\]'
}

_perl_m_opt () {
  compset -P '-'

  if compset -P '*='; then
    _message 'module arguments, comma separated'
  else
    _perl_modules -S= -q
  fi
}

_perl_config_vars () {
  if (( ! $+_perl_config_vars )); then
    # perl | perl ... nasty, but is there another way?
    _perl_config_vars=( $(perl -V |
			    perl -ne 'push @m, (/(\w+)(?==)/g);' \
			         -e  'END {print join "\n", @m}' ) )
  fi

  local add_colon='-P:'
  compset -P '*:' && add_colon=''

  local delimiter='\ '
  (( compstate[quoting] )) && delimiter=' '

  compset -P '* ' && compset -q
  compadd "$expl[@]" $add_colon -S$delimiter -q -a _perl_config_vars
}

_perl "$@"