• Immutable Page
  • Info
  • Attachments

roelkluin/cvars howto

You have to source cvars to use these tools and run these commands in your git Linux kernel directory.


gg does something like

git grep -n -E [other_options] "$(bli2 "$1")"


bli2() parses a string and transforms it into a more complex extended regexp, which it simply echoes.

To understand how it parses things try these:

bli2 "@V"
bli2 "@d"
bli2 " "
bli2 "

Note that @V will catch the identifier of a simple local variable, @d will catch a number (even if it's a hex or 1ull), spaces are squeezed and parsed to match optional spaces.

bli2 pattern

description of what is echoed

echoed string (literally)

number of back-references

any space

optional space




exclamation mark (because bash otherwise bangs)




obligatory space








identifier in only uppercases




a non-alnumeric




a non-alnumeric or extension to the left of a variable




(pointer) member, array

see `bli2 "@w"'



any number

bli2 "@d"



any number of lines, subsequent matches on the beginning of the next line




up to 2 nested parentheses

bli2 "\(...\)"



up to 2 nested curly brackets

bli2 "\{...\}"



up to 2 nested square brackets

bli2 "\[...\]"



characters optionally followed by up to 2 nested parentheses

bli2 "\(-..\)"



characters optionally followed by up to 2 nested curly brackets

bli2 "\{-..\}"



up to 8 nested curly brackets

bli2 "\(.8.\)"



prior conditions

bli2 "@...&|@"



later conditions

bli2 "@&|...@"



conditions inbetween

bli2 "@&|...&|@"



a branch

bli2 "@branch"



in a branch

bli2 "@in_branch"



I wrote this to do a multiline (git-)grep, See examples. gres does something in the order of:

git grep -E -n -other_opts "$(bli2 "$1")" -- '*.c' '*.h' | sed -n -r "$(ecsed2 "${@:2})"

with `gres -B1 -A40 "pattern1" "pattern2" "..."' the `-B1' and `-A40' are passed to git-grep, bli2() parses the first pattern to a extended regexp query. Subsequent patterns are passed to ecsed2() which are used to create a sed script. With this script, sed parses the `git grep' output and prints only the output of which the last - but not prior - patterns matched.

The sed script transforms the first of the `path/to/filename.c-301-' into a vi command, the remainder are removed. Until an end-of-function- or end-of-match-pattern occurs, lines are extended. Any comments are removed. For each match that `git grep' piped to sed, (parsed) matches are displayed if no exclusion pattern matched and the last pattern matched.

Tell others about this page:

last edited 2010-01-20 01:23:42 by roelkluin