Tuesday, July 14, 2020

rm != rg

I use ripgrep, rg. It's like recursive grep, only 100x better.

Today, I had this session:

$ rm pattern
rm: pattern: No such file or directory
$ rg pattern
$

See that? I meant to type "rg pattern" the first time, but typed "rm pattern". Luckily no harm was done in this case. But what if I had typed "rm tod*", wanting to search for the string "to" followed by zero or more "d"? Well, I might just blow away my todo file, since it matches the glob tod*. And then I'd be sad.

I'm not sure if the ergomomics of rg as a command name have come up before, but this scary close encounter has me thinking. Maybe I should do this sly manuever, as suggested by a colleague: alias ag=rg.

I don't know. I think I'm tempted more so to make rm with its dangerous side effects harder to invoke. Like so:

alias remove=rm
rm() {
  echo "If you want to destroy a file, use remove."
  echo "If you want to find a file, use rg."
}

What do you think?

0 comments:

Post a Comment

Share your thoughts!