lucc / nvimpager

Use nvim as a pager to view manpages, diffs, etc with nvim's syntax highlighting
Other
366 stars 19 forks source link

When wrapping with Nix to set arguments, always uses `cat` mode #89

Closed spikespaz closed 11 months ago

spikespaz commented 11 months ago

I have the following Nix derivation, which will replace the nvimpager command with a wrapper script:

nvimpager' = pkgs.nvimpager.overrideAttrs (self: super: {
  nativeBuildInputs = super.nativeBuildInputs or [ ] ++ [ pkgs.makeWrapper ];
  postInstall = super.postInstall or "" + ''
    wrapProgram $out/bin/nvimpager \
      --add-flags '-p -c "lua nvimpager.maps = false; lua nvimpager.git_colors = true"'
  '';
});

This is the content of the script:

#! /nix/store/ir0j7zqlw9dc49grmwplppc7gh0s40yf-bash-5.2-p15/bin/bash -e
exec -a "$0" "/nix/store/gms73z8zvfps98rdkcf2r5xs1pbay0lc-nvimpager-0.12.0/bin/.nvimpager-wrapped"  -p -c "lua nvimpager.maps = false; lua nvimpager.git_colors = true" "$@"

When I use the pager for anything from STDIN, it always just prints out the content (syntax highlighted) to my terminal.

lucc commented 11 months ago

In your script you have the options -p -c which are both parsed by nvimpager. Nvim options can only be given after -- or after a file argument.

spikespaz commented 11 months ago

If they're parsed by nvimpager why do they need to be after --?

spikespaz commented 11 months ago

Oh I see, I need to end the arguments parsed by nvimpager with --.

spikespaz commented 11 months ago

Nope, that doesn't work.

#! /nix/store/ir0j7zqlw9dc49grmwplppc7gh0s40yf-bash-5.2-p15/bin/bash -e
exec -a "$0" "/nix/store/14qsc1x1i7wwqr6kn2vdxk4wy100dwgi-nvimpager-0.12.0/bin/.nvimpager-wrapped"  -p -c "lua nvimpager.maps = false; lua nvimpager.git_colors = true" -- "$@"
lucc commented 11 months ago

You need nvimpager -p -- -c "lua nvimpager.maps ..." because you want to use the -c option of nvim but are actually using the -c option of nvimpager (with a file nameof "lua nvimpager.maps = ..." which probably does not exist).

spikespaz commented 11 months ago

Alright, I've got that. Now what is the correct way to set multiple attributes with Lua?

Error detected while processing command line:
E5107: Error loading lua [string ":lua"]:1: '=' expected near 'nvimpager'
lucc commented 11 months ago

You are mixing vim script and lua. You need lua nvimpager.maps = false; nvimpager.git_colors = true