0

I'm trying to apply this approach in a more generic way. I adopted the code in ~/.zshrc as follows:

  27   │ irg() {
  28   │   RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
  29   │   INITIAL_QUERY="${*:-}"
  30 ~ │   FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \
  31 ~ │   fzf --ansi \
  32 ~ │       --color "hl:-1:underline,hl+:-1:underline:reverse" \
  33 ~ │       --disabled --query "$INITIAL_QUERY" \
  34 ~ │       --bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
  35 ~ │       --bind "ctrl-f:unbind(change,ctrl-f)+change-prompt(2. fzf> )+enable-search+clear-query+rebind(ctrl-r)" \
  36 ~ │       --bind "ctrl-r:unbind(ctrl-r)+change-prompt(1. ripgrep> )+disable-search+reload($RG_PREFIX {q} || true)+rebind(change,ctrl-f)" \
  37 ~ │       --prompt '1. Ripgrep> ' \
  38 ~ │       --delimiter : \
  39 ~ │       --header '╱ CTRL-R (Ripgrep mode) ╱ CTRL-F (fzf mode) ╱' \
  40 ~ │       --preview 'bat --color=always {1} --highlight-line {2}' \
  41 ~ │       --preview-window 'up,60%,border-bottom,+{2}+3/3,~3'
  42   │ }

and my desired result is to use the function as a regular linux command, pipelining the output to some other utils like so:

irg someReg | cat or irg someReg | code -r

Apparently, that's now how it is supposed to be done as the output of echo is not used. Any help is very much appreciated.

v8vb
  • 49
  • 9
  • You can pipe the output of a function into another command. You can easily verify this by doing, for instance `fa() echo x` and then `fa|xxd`. What do you see when you do a `irg someReg|xxd`? – user1934428 Aug 05 '22 at 08:01

1 Answers1

0

A solution is to use command substitution like so:

code -r -g $(irg <pattern> | cut -d: -f1,2,3)
v8vb
  • 49
  • 9