diff --git a/modules/fish/ff.bash b/modules/fish/ff.bash new file mode 100644 index 0000000..20c7cbe --- /dev/null +++ b/modules/fish/ff.bash @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# Switch between Ripgrep launcher mode (CTRL-R) and fzf filtering mode (CTRL-F) +rm -f /tmp/rg-fzf-{r,f} +RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case " +INITIAL_QUERY="${*:-}" +fzf --ansi --disabled --query "$INITIAL_QUERY" \ + --bind "start:reload($RG_PREFIX {q})+unbind(ctrl-r)" \ + --bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \ + --bind "ctrl-f:unbind(change,ctrl-f)+change-prompt(2. fzf> )+enable-search+rebind(ctrl-r)+transform-query(echo {q} > /tmp/rg-fzf-r; cat /tmp/rg-fzf-f)" \ + --bind "ctrl-r:unbind(ctrl-r)+change-prompt(1. ripgrep> )+disable-search+reload($RG_PREFIX {q} || true)+rebind(change,ctrl-f)+transform-query(echo {q} > /tmp/rg-fzf-f; cat /tmp/rg-fzf-r)" \ + --color "hl:-1:underline,hl+:-1:underline:reverse" \ + --prompt '1. ripgrep> ' \ + --delimiter : \ + --header '╱ CTRL-R (ripgrep mode) ╱ CTRL-F (fzf mode) ╱' \ + --preview 'bat --color=always {1} --highlight-line {2}' \ + --preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \ + --bind 'enter:become(vim {1} +{2})' diff --git a/modules/fish/work.nix b/modules/fish/work.nix index 93402e6..32b9811 100644 --- a/modules/fish/work.nix +++ b/modules/fish/work.nix @@ -68,19 +68,7 @@ end ''; ff = '' - set rg_cmd "rg --column --line-number --no-heading --color=always --smart-case" - set initial_query (string join " " $argv) - - fzf --ansi --disabled --query "$initial_query" \ - --bind "start:reload:$rg_cmd {q}" \ - --bind "change:reload:sleep 0.1; $rg_cmd {q} || true" \ - --bind "alt-enter:unbind(change,alt-enter)+change-prompt(2. fzf> )+enable-search+clear-query" \ - --color "hl:-1:underline,hl+:-1:underline:reverse" \ - --prompt '1. ripgrep> ' \ - --delimiter : \ - --preview 'bat --color=always {1} --highlight-line {2}' \ - --preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \ - --bind 'enter:become(nvim {1} +{2})' + bash ${./ff.bash} ''; envsource = '' for line in (cat $argv | grep -v '^#')