Coder Social home page Coder Social logo

Utility command: Generate a new ID about zk HOT 4 CLOSED

nogweii avatar nogweii commented on July 19, 2024
Utility command: Generate a new ID

from zk.

Comments (4)

mickael-menu avatar mickael-menu commented on July 19, 2024

I'd like to avoid exposing internal utilities to keep the CLI interface simple.

However, I've been thinking of two different features that could produce a similar output. Both of these solutions assume you have a template at ~/.config/zk/templates/id.md containing:

{{id}}

First option, a new --dry-run flag for zk new, which instead of writing the file would:

  • Print to stderr the new note file path.
  • Print to stdout the content of the generated note, as it would have been written at the path.

In your case, you could use it like this:

$ zk new --dry-run --template id 2> /dev/null
a65c8b45d

The second option is similar: adding a new command dedicated to render a template. I think this could be useful to expand templates inside notes that are already existing, for example to add a YAML frontmatter.

I'm not sure exactly how it would look like, but it could be something like:

$ zk render id
a65c8b45d

What do you think? The --dry-run flag could be faster to implement as its semantics are clear. Eventually, both solutions could be useful to have.

Also for which use case do you need this exposed in the LSP server? I guess the dry-run flag could be exposed for zk.new and the returned value could be a JSON with keys path and content.

from zk.

nogweii avatar nogweii commented on July 19, 2024

Adding --dry-run to new would solve my use case, so that would be nice.

Adding a render command would be very interesting. Either solution solves my use case, so I'd leave it to you to decide which path to pursue first.

Also for which use case do you need this exposed in the LSP server?

Thinking about it some more, it's not super useful to be directly exposed in the LSP server. I was thinking it would be easier to thus bind it to a keyboard shortcut; I could just as easily launch the zk CLI with whichever solution. So it's not necessary for my use case.

Also thinking about this some more, I forgot about the {{ content }} template value, so some of this feature request is unnecessary. I do think either solution provides really useful tools for further scripting, so I'll leave this issue open for now, but feel free to close if you prefer.

from zk.

mickael-menu avatar mickael-menu commented on July 19, 2024

Okay, I'll go with --dry-run for now as it would be useful to debug templates and note configuration as well.

from zk.

mickael-menu avatar mickael-menu commented on July 19, 2024

@nogweii It's available in main

$ cat .zk/templates/id.md
{{id}}

$ zk new --dry-run --template id.md 2> /dev/null
ymkh

You might need to strip the extra newline that is appended to every generated note to only get the ID.

from zk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.