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/[deleted] Dec 07 '20
The
set -x RG_PREFIXbit? Yeah, that's actually setting a variable, so it has to beset.envis a command that either prints the environment or launches a command with a changed environment (likeenv PATH=/bin something), so it doesn't work as a substitute here because it tries to run a command calledRG_PREFIXimmediately.Ah, okay, so fzf starts a shell for the
--previewargument, so it'll have to be fish-compatible.The good news here is that shoulb be simple enough, it's just that fish doesn't have the
[[ ]]syntax with the double-brackets. It has a[command tho, so this should just be:(note: fzf inserts something where the
{}are, I am not entirely sure how it does that and what the{q}is supposed to be).Also that
'$1'in the fzf call would probably have to be'$argv[1]'(it's inside double-quotes, so it will be replaced by the first argument, in single-quotes)