ELLIOTTCABLE
ELLIOTTCABLE

Reputation: 18029

How can I bypass a recursive function-definition in a shell function?

I want to add a function like the following to my .zshrc:

rg() { rg "$@" --pretty less -XFRS ;}

Problem is, this causes an infinite loop upon invocation.

I thought that single-quoting the command's name ('rg' --pretty …) bypassed locally-defined functions and aliases; but that failed to prevent the infinite-loop, for some reason.

I can implement this with an absolute path,

rg() { /usr/local/bin/rg "$@" --pretty less -XFRS ;}

… but I don't want to lose $PATH-resolution of the program; I just want to bypass the function.

Upvotes: 2

Views: 368

Answers (1)

anubhava
anubhava

Reputation: 785008

You can use command builtin:

rg() { command rg "$@" --pretty less -XFRS ;}

This runs given COMMAND with ARGS suppressing shell function lookup, or display information about the specified COMMANDs.

Upvotes: 2

Related Questions