From 8575c378551fb24ba9589af0d36dd1ba9879aa7b Mon Sep 17 00:00:00 2001 From: Khairul Azhar Kasmiran Date: Sun, 2 Feb 2025 10:40:42 +0800 Subject: [PATCH] `^` grep op: Skip whitespace --- librz/cons/grep.c | 5 ++++- librz/core/cmd_descs/cmd_descs.c | 2 +- librz/core/cmd_descs/cmd_descs.yaml | 2 +- test/db/cmd/cmd_i | 2 ++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/librz/cons/grep.c b/librz/cons/grep.c index 9636bb36426..dabb8128511 100644 --- a/librz/cons/grep.c +++ b/librz/cons/grep.c @@ -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", @@ -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; diff --git a/librz/core/cmd_descs/cmd_descs.c b/librz/core/cmd_descs/cmd_descs.c index baf9a2f48f3..b19f68f8105 100644 --- a/librz/core/cmd_descs/cmd_descs.c +++ b/librz/core/cmd_descs/cmd_descs.c @@ -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" }, diff --git a/librz/core/cmd_descs/cmd_descs.yaml b/librz/core/cmd_descs/cmd_descs.yaml index 471f8e58576..b5e77e3df7f 100644 --- a/librz/core/cmd_descs/cmd_descs.yaml +++ b/librz/core/cmd_descs/cmd_descs.yaml @@ -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: "!" diff --git a/test/db/cmd/cmd_i b/test/db/cmd/cmd_i index b2731a64f8a..8b3a3ececf0 100644 --- a/test/db/cmd/cmd_i +++ b/test/db/cmd/cmd_i @@ -4883,9 +4883,11 @@ FILE== CMDS=<