From 6ef86098cb454cbd0547e87f36f6d54827b723d9 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 10 Jul 2024 03:52:48 -0400 Subject: [PATCH] fix(ivy): counsel-rg dying on non-zero exit code Monkey-patches counsel-rg to ignore non-zero exit codes. This may have other side effects, but despite it still producing workable resutls, the command will discard all its results if there are any errors while scanning a directory. Ref: abo-abo/swiper#2339 Fix: #3038 --- modules/completion/ivy/config.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index e537abf81..3372ab758 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -211,6 +211,20 @@ results buffer.") (when (stringp counsel-rg-base-command) (setq counsel-rg-base-command (split-string counsel-rg-base-command))) + ;; REVIEW: See abo-abo/swiper#2339. + (defadvice! +counsel-rg-suppress-error-code-a (fn &rest args) + "Ripgrep returns a non-zero exit code if it encounters any trouble (e.g. you +don't have the needed permissions for a couple files/directories in a project). +Even if rg continues to produce workable results, that non-zero exit code causes +counsel-rg to discard the rest of the output to display an error. + +This advice suppresses the error code, so you can still operate on whatever +workable results ripgrep produces, despite the error." + :around #'counsel-rg + (letf! (defun process-exit-status (code) + (funcall process-exit-status (if (= code 2) 0 code))) + (apply fn args))) + ;; Integrate with `helpful' (setq counsel-describe-function-function #'helpful-callable counsel-describe-variable-function #'helpful-variable