diff --git a/minimal/hm.nix b/minimal/hm.nix index 4d7826c..aba3904 100644 --- a/minimal/hm.nix +++ b/minimal/hm.nix @@ -38,6 +38,7 @@ tokei unzip wget + frg # Useful for pandoc to latex (texlive.combine { diff --git a/pkgs/default.nix b/pkgs/default.nix index 6ed0978..4afcccd 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -17,4 +17,5 @@ inherit naersk; dotacatSrc = sources.dotacat; }; + frg = callPackage ./frg.nix {}; } diff --git a/pkgs/frg.nix b/pkgs/frg.nix new file mode 100644 index 0000000..27ae20d --- /dev/null +++ b/pkgs/frg.nix @@ -0,0 +1,37 @@ +{ + stdenv, + writeText, + fzf, + ripgrep, + bat, +}: +stdenv.mkDerivation { + pname = "frg"; + version = "0.1.0"; + + dontUnpack = true; + + installPhase = let + script = writeText "frg" '' + #!/usr/bin/env bash + + # 1. Search for text in files using Ripgrep + # 2. Interactively restart Ripgrep with reload action + # 3. Open the file in Vim + RG_PREFIX="${ripgrep}/bin/rg --column --line-number --no-heading --color=always --smart-case " + INITIAL_QUERY="''${*:-}" + FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \ + ${fzf}/bin/fzf --ansi \ + --disabled --query "$INITIAL_QUERY" \ + --bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \ + --delimiter : \ + --preview '${bat}/bin/bat --color=always {1} --highlight-line {2}' \ + --preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \ + --bind "enter:become($EDITOR {1} +{2})" + ''; + in '' + mkdir -p $out/bin + cp ${script} $out/bin/frg + chmod +x $out/bin/frg + ''; +}