File: grep

package info (click to toggle)
yash 2.60-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,152 kB
  • sloc: ansic: 34,578; makefile: 851; sh: 808; sed: 16
file content (119 lines) | stat: -rw-r--r-- 5,833 bytes parent folder | download
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
110
111
112
113
114
115
116
117
118
119
# (C) 2010 magicant

# Completion script for the "grep" command.
# Supports POSIX 2008, GNU grep 2.6.3, SunOS 5.10, HP-UX 11i v3.

function completion/grep {

        case $("${WORDS[1]}" --version 2>/dev/null) in
                (*'GNU grep'*) typeset type=GNU ;;
                (*)            typeset type="$(uname 2>/dev/null)" ;;
        esac
        case $type in
                (GNU) typeset long=true ;;
                (*)   typeset long= ;;
        esac

        typeset OPTIONS POSIXOPTIONS ADDOPTIONS ARGOPT PREFIX
        POSIXOPTIONS=( #>#
        "c ${long:+--count}; print only the count of selected lines"
        "E ${long:+--extended-regexp}; use extended regular expression"
        "e: ${long:+--regexp:}; specify a pattern to match"
        "F ${long:+--fixed-strings}; perform simple string matching rather than regular expression"
        "f: ${long:+--file:}; specify a file containing patterns to match"
        "i ${long:+--ignore-case}; case-insensitive matching"
        "l ${long:+--files-with-matches}; print filenames only"
        "n ${long:+--line-number}; print line numbers"
        "q ${long:+--quiet --silent}; don't print anything to the standard output"
        "s ${long:+--no-messages}; suppress error messages"
        "v ${long:+--invert-match}; select non-matching lines"
        "x ${long:+--line-regexp}; force the pattern to match whole lines only"
        ) #<#

        ADDOPTIONS=()
        case $type in (GNU|SunOS|HP-UX)
                ADDOPTIONS=("$ADDOPTIONS" #>#
                "h ${long:+--no-filename}; never print filenames in results"
                "w ${long:+--word-regexp}; force the pattern to match whole words only"
                ) #<#
        esac
        case $type in
        (GNU)
                ADDOPTIONS=("$ADDOPTIONS" #>#
                "A: --after-context:; print specified number of lines after each line printed"
                "a --text; treat binary files as test files"
                "B: --before-context:; print specified number of lines before each line printed"
                "b --byte-offset; print byte offset for each line printed"
                "C: --context:; print specified number of lines before and after each line printed"
                "D: --devices:; specify how to handle special files"
                "d: --directories:; specify how to handle directories"
                "G --basic-regexp; use basic regular expression"
                "H --with-filename; always print the filename for each line printed"
                "I; assume binary files don't match anything"
                "L --files-without-match; print only the names of files containing no selected lines"
                "m: --max-count:; specify the count to match at most"
                "o --only-matching; print only the matching part of line"
                "P --perl-regexp; use Perl's regular expression"
                "R r --recursive; recursively search directories"
                "T --initial-tab; align result lines"
                "U --binary; don't convert CR-LF into LF"
                "u --unix-byte-offsets; report offsets ignoring carriage returns"
                "V --version; print version info"
                "Z --null; print a null byte after each filename"
                "z --null-data; separate output lines with null byte rather than newline"
                "--binary-files:; specify how to handle binary files"
                "--color:: --colour::; specify when to print colored output"
                "--exclude:; skip files whose names match the specified pattern"
                "--exclude-dir:; skip directories whose names match the specified pattern"
                "--exclude-from:; skip files whose names match a pattern in the specified file"
                "--include:; search only files whose names match the specified pattern"
                "--label:; specify a filename for the standard output"
                "--line-buffered; print results as soon as possible"
                "--help"
                ) #<#
                ;;
        (SunOS|HP-UX)
                ADDOPTIONS=("$ADDOPTIONS" #>#
                "b; print 512-block offset for each line printed"
                ) #<#
                ;;
        esac

        OPTIONS=("$POSIXOPTIONS" "$ADDOPTIONS")
        unset POSIXOPTIONS ADDOPTIONS

        command -f completion//parseoptions ${long:+-es}
        case $ARGOPT in
        (-)
                command -f completion//completeoptions
                ;;
        ([ABCm]|--*context|--max-count)
                ;;
        (--binary-files) #>>#
                complete -P "$PREFIX" -D "report but don't print the contents of binary files" binary
                complete -P "$PREFIX" -D "assume binary files don't match anything" without-match
                complete -P "$PREFIX" -D "treat binary files as test files" text
                ;; #<<#
        (--color|--colour) #>>#
                complete -P "$PREFIX" -D "always print in color" yes always force
                complete -P "$PREFIX" -D "print in color if output is terminal" auto tty if-tty
                complete -P "$PREFIX" -D "don't print in color" no never none
                ;; #<<#
        (D|--devices) #>>#
                complete -P "$PREFIX" -D "treat special files as regular files" read
                complete -P "$PREFIX" -D "skip special files" skip
                ;; #<<#
        (d|--directories) #>>#
                complete -P "$PREFIX" -D "treat directories as regular files" read
                complete -P "$PREFIX" -D "recursively search directories" recurse
                complete -P "$PREFIX" -D "skip directories" skip
                ;; #<<#
        (*)
                complete -P "$PREFIX" -f
                ;;
        esac

}


# vim: set ft=sh ts=8 sts=8 sw=8 et: