On 07/11/2024 16:24, Xi Lu wrote:
+++ b/lisp/org-mouse.el
@@ -627,7 +627,7 @@ This means, between the beginning of line and the point."
["Sparse Tree" (org-occur ',region-string)]
["Find in Buffer" (occur ',region-string)]
["Grep in Current Dir"
- (grep (format "grep -rnH -e '%s' *" ',region-string))]
+ (grep (format "grep -rnH -e '%s' ./*" ',region-string))]
Thanks, I find it as an acceptable quick fix despite it adds noisy "./"
to file names that are not started with "-". In BASH it is possible to
do something like
shopt -s nullglob; echo ./-* [!-]*
but it is not portable (and portable [!CHAR] negation may be treated as
history expansion by some *interactive* shells).
Xi Lu, is it a kind of friendly trolling that you submitted a patch with
a workaround for leading dash file name pitfall, but you decided to keep
ability to pass arbitrary shell code as selection? Just quotes is a poor
way to protect against shell specials and it can be easily bypassed.
P.S. This code needs some love. I would expect `grep-command' or
`grep-find-command' variable should be respected here. There are grep
alternatives that respect VCS ignore files and thus work much faster.
However it is for another patch, not for this thread.
I am in doubts if "-F" should be added. Literal search for *selected*
text is more reasonable from my point of view.
grep -rnH -e '[aa' ./*
grep: Unmatched [, [^, [:, [., or [=
P.P.S. Some links for the context of leading dash issues:
- <https://www.shellcheck.net/wiki/SC2035>
"Use ./*glob* or -- *glob* so names with dashes won't become options."
- <https://www.openwall.com/lists/oss-security/2024/11/06/1>
"shell wildcard expansion (un)safety" Wed, 6 Nov 2024 05:12:15 +0100
- <https://mywiki.wooledge.org/BashPitfalls#pf3>
3. Filenames with leading dashes