File: git-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 (123 lines) | stat: -rw-r--r-- 5,190 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
120
121
122
123
# (C) 2013-2025 magicant

# Completion script for the "git-grep" command.
# Supports Git 2.48.1.

function completion/git-grep {
        WORDS=(git grep "${WORDS[2,-1]}")
        command -f completion//reexecute
}

function completion/git::grep:arg {

        OPTIONS=( #>#
        "A: --after-context:; print specified number of lines after each line printed"
        "--all-match; require all patterns to match in each file"
        "--and; join two patterns"
        "a --text; treat binary files as test files"
        "B: --before-context:; print specified number of lines before each line printed"
        "--break; insert an empty line between matches from different files"
        "--cached; search files in the index"
        "--color::; specify when to print colored output"
        "--column; print column numbers"
        "C: --context:; print specified number of lines before and after each line printed"
        "c --count; print only the count of selected lines"
        "E --extended-regexp; use extended regular expression"
        "e:; specify a pattern to match"
        "--exclude-standard; don't search ignored files"
        "F --fixed-strings; perform simple string matching rather than regular expression"
        "f: --file:; specify a file containing patterns to match"
        "--full-name; print filenames relative to the working tree's root directory"
        "G --basic-regexp; use basic regular expression"
        "H; always print the filename for each line printed"
        "h; never print filenames in results"
        "--heading; print filenames in separate lines"
        "I; assume binary files don't match anything"
        "i --ignore-case; case-insensitive matching"
        "L --files-without-match; print only the names of files containing no selected lines"
        "l --files-with-matches --name-only; print filenames only"
        "m: --max-count:; limit the number of matches per file"
        "--max-depth:; specify directory depth to limit search"
        "n --line-number; print line numbers"
        "--no-color; like --color=never"
        "--no-exclude-standard; search ignored files"
        "--no-index; search files outside a working tree"
        "--no-recursive; only search the operand directory"
        "--not; negate a pattern"
        "--no-textconv; ignore textconv settings"
        "O:: --open-files-in-pager::; open matching files in a pager"
        "o --only-matching; print only the matching part of line"
        "--or; join two patterns"
        "p --show-function; print the name of the function containing the match"
        "P --perl-regexp; use Perl's regular expression"
        "q --quiet; don't print anything to the standard output"
        "r --recursive; search subdirectories recursively"
        "--recurse-submodules; search submodules as well"
        "--textconv; honor textconv settings"
        "--threads:; specify the number of worker threads"
        "--untracked; search untracked files as well"
        "v --invert-match; select non-matching lines"
        "W --function-context; print the whole functions containing matches"
        "w --word-regexp; force the pattern to match whole words only"
        "z --null; print a null byte after each filename"
        ) #<#

        command -f completion/git::grep:removeparen
        command -f completion//parseoptions -n
        case $ARGOPT in
                (-)
                        command -f completion//completeoptions
                        ;;
                ([ABC]|--*context|--max*|--threads)
                        ;;
                (--color)
                        command -f completion/git::--color:arg
                        ;;
                (O|--open-files-in-pager)
                        complete -P "$PREFIX" --external-command
                        ;;
                ('')
                        if command -f completion/git::grep:shouldcompleteuntracked; then
                                complete -P "$PREFIX" -f
                        fi
                        command -f completion/git::completerefpath
                        ;;
                (*)
                        complete -P "$PREFIX" -f
                        ;;
        esac

}

function completion/git::grep:removeparen {
        typeset i=2
        while [ "$i" -le "${WORDS[#]}" ]; do
                case ${WORDS[i]} in
                        ([\(\)])
                                # remove this parenthesis
                                WORDS=("${WORDS[1,i-1]}" "${WORDS[i+1,-1]}") ;;
                        (--)
                                break ;;
                        (*)
                                : $((i++)) ;;
                esac
        done
        : words = "$WORDS"
}

function completion/git::grep:shouldcompleteuntracked {
        typeset i=2
        while [ "$i" -le "${WORDS[#]}" ]; do
                case ${WORDS[i]} in
                        (--no-index|--untracked)
                                return 0;;
                        (--)
                                return 1;;
                esac
                : $((i++))
        done
        return 1
}


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