From abaf191c6f8363699b0bb5a222ed4a61e8d1e3d7 Mon Sep 17 00:00:00 2001 From: "Gustavo L de Mello (Guz)" Date: Sun, 8 Dec 2024 19:39:38 -0300 Subject: [PATCH] feat(tweaks): grip markdown viewer --- flake.nix | 26 +++++++++++++++++++++++++- lua/dot013/tweaks.lua | 41 +++++++++++++++++++++++++++++++++++++++++ neovim.nix | 5 ++++- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index a6d27ab..ca58480 100644 --- a/flake.nix +++ b/flake.nix @@ -23,11 +23,35 @@ pkgs = import nixpkgs {inherit system overlays;}; in f system pkgs); + + grip = { + pkgs, + lib, + }: let + gripConf = pkgs.writeText "settings.py" '' + HOST = "0.0.0.0" + ''; + gripHome = pkgs.stdenv.mkDerivation { + name = "grip-conf"; + src = gripConf; + phases = ["installPhase"]; + installPhase = '' + mkdir -p $out + cp $src $out/settings.py + ''; + }; + in + pkgs.writeShellScriptBin "grip" '' + export GRIPHOME="${gripHome}" + ${lib.getExe pkgs.python312Packages.grip} "$@" + ''; in { packages = forAllSystems (system: pkgs: { - neovim = pkgs.callPackage ./neovim.nix {}; + grip = pkgs.callPackage grip {}; + neovim = pkgs.callPackage ./neovim.nix {inherit self;}; default = self.packages.${system}.neovim; }); + devShells = forAllSystems (system: pkgs: { default = pkgs.mkShell { buildInputs = with pkgs; [ diff --git a/lua/dot013/tweaks.lua b/lua/dot013/tweaks.lua index 9de2888..987dcdf 100644 --- a/lua/dot013/tweaks.lua +++ b/lua/dot013/tweaks.lua @@ -8,6 +8,47 @@ vim.api.nvim_create_autocmd("TextYankPost", { pattern = "*", }) +local grip_channel = nil +vim.api.nvim_create_user_command("GripStart", function() + if grip_channel then + return + end + + local file = vim.api.nvim_buf_get_name(0) + + local cmd = "grip " .. file + + grip_channel = vim.fn.jobstart(cmd, { + stderr_buffered = true, + on_stderr = function(_, err) + vim.fn.jobstop(grip_channel) + + local content = table.concat(err, "\n") + if content:len() > 0 then + vim.api.nvim_notify("Grip error: " .. content, vim.log.levels.ERROR, {}) + end + end, + on_exit = function() + vim.fn.chanclose(grip_channel) + grip_channel = nil + end, + }) +end, {}) + +vim.api.nvim_create_user_command("GripStop", function() + if grip_channel then + vim.fn.jobstop(grip_channel) + end +end, {}) + +vim.api.nvim_create_autocmd("Quit", { + callback = function() + if grip_channel then + vim.fn.jobstop(grip_channel) + end + end, +}) + -- Move when highlighted vim.keymap.set("n", "J", "mzJ`z") diff --git a/neovim.nix b/neovim.nix index 528d4f2..75f1be6 100644 --- a/neovim.nix +++ b/neovim.nix @@ -1,4 +1,5 @@ { + self, symlinkJoin, makeWrapper, runCommandLocal, @@ -83,8 +84,10 @@ ]; packages = with pkgs; [ - ripgrep lf + ripgrep + + self.packages.${pkgs.system}.grip ]; foldPlugins = builtins.foldl' (acc: next: acc ++ [next] ++ (foldPlugins (next.dependencies or []))) [];