Coder Social home page Coder Social logo

Comments (4)

linrongbin16 avatar linrongbin16 commented on September 17, 2024 1

thanks for education, much clear for me

from luv.

squeek502 avatar squeek502 commented on September 17, 2024

Going from a string with quotes, etc to a list of arguments is typically handled by the shell, and each shell can do things differently (how to escape things, what needs to be escaped, etc), so there's no one correct way to do it AFAIK.

I believe what you'd want for those two commands would be:

{
  "git",
  "log",
  "--pretty=%C(yellow)%h %C(cyan)%cd %C(green)%aN%C(auto)%d %Creset%s",
  "--date=short",
}

and

{
  "rg",
  "--no-heading",
  "--column",
  "--",
  "fzf",
}

from luv.

linrongbin16 avatar linrongbin16 commented on September 17, 2024

Hi, thanks to confirm.

I have one more question, how does the quotes and escaping characters handled by uv.spawn?

In your sample code, there's no single quote ' around the %C(yellow)%h %C(cyan)%cd %C(green)%aN%C(auto)%d %Creset%s?

So inside uv.spawn, it will automatically add quotes for me?

from luv.

squeek502 avatar squeek502 commented on September 17, 2024

Quotes are only necessary when determining if something is a single argument or multiple arguments. Once the arguments have been split, then quotes are no longer necessary. This splitting (and therefore removal of quotes) is what the shell usually does for you.

For example, if you run something like:

myprogram "some argument"

then in myprogram you'd get some argument (without the quotes) as argv[1].

So, when calling uv.spawn, you just call it with the arguments already split, so there's no need for quotes.

There is a caveat for Windows, though, since it does actually transform it back into a single string before giving it to CreateProcess. See the options.verbatim flag if you need to do your own quoting for Windows:

options.verbatim - If true, do not wrap any arguments in quotes, or perform any other escaping, when converting the argument list into a command line string. This option is only meaningful on Windows systems. On Unix it is silently ignored.

You'll probably need to test it on Windows to make sure it does what you expect.


Oh also, the docs are wrong about options.args: the first value should not be the command/program name. Instead you'll want to do something like this:

uv.spawn("git", {
  args = {
    "log",
    "--pretty=%C(yellow)%h %C(cyan)%cd %C(green)%aN%C(auto)%d %Creset%s",
    "--date=short",
  },
})

will update the docs about that.

from luv.

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.