Skip to content

Commit

Permalink
^ grep op: Skip whitespace (#4875)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazarmy authored Feb 2, 2025
1 parent b38bf49 commit 2d039ee
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion librz/cons/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static const char *help_detail_tilde[] = {
" $!", "", "sort in inverse order",
" ,", "", "token to define another keyword",
" +", "", "case insensitive grep (grep -i)",
" ^", "", "words must be placed at the beginning of line",
" ^", "", "words must be placed at the beginning of line, after whitespace if any",
" <", "", "perform zoom operation on the buffer",
" !", "", "negate grep",
" ?", "", "count number of matching lines",
Expand Down Expand Up @@ -794,6 +794,9 @@ RZ_API int rz_cons_grep_line(char *buf, int len) {
continue;
}
if (grep->begin) {
while (p > in && IS_WHITESPACE(*(p - 1))) {
p--;
}
hit = (p == in);
if (grep->neg) {
hit = !hit;
Expand Down
2 changes: 1 addition & 1 deletion librz/core/cmd_descs/cmd_descs.c
Original file line number Diff line number Diff line change
Expand Up @@ -19171,7 +19171,7 @@ static const RzCmdDescDetailEntry grep_Modifiers_detail_entries[] = {
{ .text = "$!", .arg_str = NULL, .comment = "Sort in inverse order" },
{ .text = ",", .arg_str = NULL, .comment = "Token to define another keyword" },
{ .text = "+", .arg_str = NULL, .comment = "Set the grep as the opposite of search.case_sensitive" },
{ .text = "^", .arg_str = NULL, .comment = "Words must be placed at the beginning of line" },
{ .text = "^", .arg_str = NULL, .comment = "Words must be placed at the beginning of line, after whitespace if any" },
{ .text = "<", .arg_str = NULL, .comment = "Perform zoom operation on the buffer" },
{ .text = "!", .arg_str = NULL, .comment = "Negate grep" },
{ .text = "?", .arg_str = NULL, .comment = "Count number of matching lines" },
Expand Down
2 changes: 1 addition & 1 deletion librz/core/cmd_descs/cmd_descs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ commands:
- text: "+"
comment: "Set the grep as the opposite of search.case_sensitive"
- text: "^"
comment: "Words must be placed at the beginning of line"
comment: "Words must be placed at the beginning of line, after whitespace if any"
- text: "<"
comment: "Perform zoom operation on the buffer"
- text: "!"
Expand Down
2 changes: 2 additions & 0 deletions test/db/cmd/cmd_i
Original file line number Diff line number Diff line change
Expand Up @@ -4883,9 +4883,11 @@ FILE==
CMDS=<<EOF
wx 7500 6900 3d25 7325 7325 7300 2573 2c00 2b25 7325 7325 7300 2d25 7325 7325 7300 6361 705f 6368 6f77 6e00 6361 705f 6461
izz:/head/1:quiet
izz~^0
EOF
EXPECT=<<EOF
0 0x00000004 0x00000004 7 8 ascii =%s%s%s
0 0x00000004 0x00000004 7 8 ascii =%s%s%s
EOF
RUN

Expand Down

0 comments on commit 2d039ee

Please sign in to comment.