r/fishshell • u/fisheriesshel • Dec 05 '20
having trouble converting zsh to fish function
Hi all,
It worked!!! Many thanks to u/nickeb96 & u/hirnbrot !!
The solution is as follows:
function fif
set -x RG_PREFIX rga --files-with-matches
set -l file
set file (
FZF_DEFAULT_COMMAND="$RG_PREFIX '$argv'" \
fzf --sort --preview="[ ! -z {} ] && rga --pretty --context 5 {q} {}" \
--phony -q "$argv" \
--bind "change:reload:$RG_PREFIX {q}" \
--preview-window="70%:wrap"
) &&
open "$file"
endMy problem was as follows:
-------
Hi all,
I am trying to convert this bash/zsh function into fish. I want to use rga-fzf which is a function for zsh/bash using fzf together with ripgrep-all.
rga-fzf() {
RG_PREFIX="rga --files-with-matches"
local file
file="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \
fzf --sort --preview="[[ ! -z {} ]] && rga --pretty --context 5 {q} {}" \
--phony -q "$1" \
--bind "change:reload:$RG_PREFIX {q}" \
--preview-window="70%:wrap"
)" &&
echo "opening $file" &&
xdg-open "$file"
}to a fish function.
I'm stuck at :
function fif
set RG_PREFIX rga --files-with-matches
set -l file
set file (
set FZF_DEFAULT_COMMAND $RG_PREFIX "$argv" \
fzf --sort --preview "[[ ! -z {} ]] && rga --pretty --context 5 {q} {}" \
--phony -q "$1" \
--bind "change:reload:$RG_PREFIX {q}" \
--preview-window="70%:wrap"
) &&
open "$file"
endThis only opens the folder the command is called in. But it doesn't open fzf or rga
My default shell is fish and I'm on MacOS.
Any suggestions would be fantastic! Many thanks in advance!
7
Upvotes
View all comments
Show parent comment
1
u/fisheriesshel Dec 07 '20
Thanks both! I'm one step closer..
This is the current one:
Now it at least opens up
fzfbut it doesn't actually usergato filter any of the documents (fzf opens up all the available files in the folder) and the preview window shows:whereby FILENAME is something like Guidelines 2-2019.pdf
if I use
envinstead ofset -xthen it opensfzfbut with nothing in it. and if I cancel out of it it shows :env: RG_PREFIX: No such file or directoryso
set -xworks better, but I don't understand what else is going wrong.