summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeniss Moon <roeniss2@gmail.com>2025-07-22 01:58:09 +0900
committerGitHub <noreply@github.com>2025-07-21 18:58:09 +0200
commit537807c863a90c51a4ec6fbb6b818c3668472425 (patch)
treec5abba967997d7c339ae5b524f0392dee32b34fb
parente3e468d1388d262b0018350a1248a176bfb31660 (diff)
downloadzsh-537807c863a90c51a4ec6fbb6b818c3668472425.tar.gz
zsh-537807c863a90c51a4ec6fbb6b818c3668472425.tar.bz2
zsh-537807c863a90c51a4ec6fbb6b818c3668472425.zip
feat(alias-finder): use ripgrep if possible (#13043)
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
-rw-r--r--plugins/alias-finder/README.md8
-rw-r--r--plugins/alias-finder/alias-finder.plugin.zsh6
2 files changed, 10 insertions, 4 deletions
diff --git a/plugins/alias-finder/README.md b/plugins/alias-finder/README.md
index a9bbd0838..b24f8d4ac 100644
--- a/plugins/alias-finder/README.md
+++ b/plugins/alias-finder/README.md
@@ -11,6 +11,8 @@ plugins=(... alias-finder)
To enable it for every single command, set zstyle in your `~/.zshrc`.
+If the user has installed `rg`([ripgrep](https://github.com/BurntSushi/ripgrep)), it will be used because it's faster. Otherwise, it will use the `grep` command.
+
```zsh
# ~/.zshrc
@@ -28,7 +30,7 @@ When you execute a command alias finder will look at your defined aliases and su
Running the un-aliased `git status` command:
```sh
-╭─tim@fox ~/repo/gitopolis ‹main›
+╭─tim@fox ~/repo/gitopolis ‹main›
╰─$ git status
gst='git status' # <=== shorter suggestion from alias-finder
@@ -40,7 +42,7 @@ nothing to commit, working tree clean
Running a shorter `git st` alias from `.gitconfig` that it suggested :
```sh
-╭─tim@fox ~/repo/gitopolis ‹main›
+╭─tim@fox ~/repo/gitopolis ‹main›
╰─$ git st
gs='git st' # <=== shorter suggestion from alias-finder
## main...origin/main
@@ -48,7 +50,7 @@ gs='git st' # <=== shorter suggestion from alias-finder
Running the shortest `gs` shell alias that it found:
```sh
-╭─tim@fox ~/repo/gitopolis ‹main›
+╭─tim@fox ~/repo/gitopolis ‹main›
╰─$ gs
# <=== no suggestions alias-finder because this is the shortest
## main...origin/main
diff --git a/plugins/alias-finder/alias-finder.plugin.zsh b/plugins/alias-finder/alias-finder.plugin.zsh
index 2351a439e..6f24c7089 100644
--- a/plugins/alias-finder/alias-finder.plugin.zsh
+++ b/plugins/alias-finder/alias-finder.plugin.zsh
@@ -43,7 +43,11 @@ alias-finder() {
filter="^'?.{1,$((cmdLen - 1))}'?=" # some aliases is surrounded by single quotes
fi
- alias | grep -E "$filter" | grep -E "=$finder"
+ if (( $+commands[rg] )); then
+ alias | rg "$filter" | rg "=$finder"
+ else
+ alias | grep -E "$filter" | grep -E "=$finder"
+ fi
if [[ $exact == true ]]; then
break # because exact case is only one