frabjous/knap

Saving files to /tmp folder

cnut1648 opened this issue · 2 comments

Hello,
I love your plugin so far! Really useful for previewing markdown files.
I have a question though, is it possible to save the pandoc converted files to /tmp? For example when I preview A.md knap will automatically create a A.html, which can cause issues in a git repo in which I have to manually remove those from being tracked by git.
I wonder if there is an option to send those intermediate files into /tmp.
Thanks!

Sure, with a little trickery. I sometimes do that myself. You can define a variable in the command itself that uses a filename based on the outputname. You would need to do so both in the processing command and preview command can find them:

E.g., to get something close to the default settings (pandoc/falkon) but with the output only saved in /tmp, you could do:

let g:knap_settings = {
    \ "mdtohtml" : "tmpfile=\"/tmp/$(basename %outputfile%)\" ; pandoc --standalone %docroot% -o \"$tmpfile\"",
    \ "mdtohtmlviewerlaunch" : "tmpfile=\"/tmp/$(basename %outputfile%)\" ; falkon \"$tmpfile\""
\ }

I'm happy to help figure out how to do one for your exact routine, but in general, I expect users of the plugin to be comfortable with the command line enough to know how to do such manipulations themselves.

But you should also know about .gitignore files (see here). You could just add A.html to your .gitignore so it doesn't get tracked. That might be easier, unless you just really don't want to clutter things.

And you might notice if you cloned my repository that it itself has a .gitignore that includes "README.html" as a file to ignore. ☺

@frabjous thanks for the pointer! I managed to save it to /tmp with live-server, and here is my init.lua config (with packer)

  use {
    "frabjous/knap",
    config = function()
      local gknapsettings = {
        htmltohtmlviewerlaunch = "live-server --quiet --browser=google-chrome-stable --open=%outputfile% --watch=%outputfile% --wait=800 /tmp",
        htmltohtmlviewerrefresh = "none",
        mdtohtml="tmpfile=\"/tmp/$(basename %outputfile%)\" ; pandoc --standalone %docroot% -o \"$tmpfile\"",
        mdtohtmlviewerlaunch = "live-server --quiet --browser=google-chrome-stable --open=%outputfile% --watch=%outputfile% --wait=800 /tmp",
        mdtohtmlviewerrefresh = "none",
      }
      vim.g.knap_settings = gknapsettings
    end
  }