Git Product home page Git Product logo

Comments (6)

SamuelSwartzberg avatar SamuelSwartzberg commented on June 4, 2024 1

I'm fairly sure that you don't need to change anything in broot for this. As you might be aware, shell doesn't have a strong distinction between one and multiple args. As far as I can see, broot just passes anything you specify as an arg to the function as a single, un-split string, but there is no rule saying that you can't just split the string yourself, either just using the shell's word-splitting, or by using your own splitting, e.g. by changing the IFS variable.

In your case, that would be

#!/bin/bash

dir="$1"
shift

for var in $*
do
    mkdir -p "$dir/$var"
done

Unless I missed or misunderstood something?

from broot.

CabalCrow avatar CabalCrow commented on June 4, 2024 1

@SamuelSwartzberg That is exactly what I wanted! Thanks a lot!

from broot.

SamuelSwartzberg avatar SamuelSwartzberg commented on June 4, 2024 1

What do you mean by 'use "'?

Given

[[verbs]]
invocation = "printargs {args}"
external = "echo {args}"

as a simple test verb:

:printargs foo "bar" baz
> foo "bar" baz

So they are preserved. If you mean 'prevent splitting on whitespace', that's true. I'm pretty sure there's a way around this, probably using eval, but once you're going down that road, you gotta wonder if you shouldn't be doing things differently. So it might be worth trying if you need the solution soon, but else, I also would kinda support an option for verbs that's something like no_quote_args, where all it does is pass the args down to the command raw, with no shell quoting and escaping. I do think that would be the cleaner solution, relying on shell resplitting is always non-ideal. Shellcheck warns you against it, for example.

from broot.

Canop avatar Canop commented on June 4, 2024

What would be MakeMulipleDirs in this case ? An internal (predefined operation in broot) or an external program ?

from broot.

CabalCrow avatar CabalCrow commented on June 4, 2024

MakeMultipleDirs would be a custom verb. Something like

{
        invocation: MakeMultipleDirs [dirs]
        shortcut: mmd
        execution: "mkmuldirs {directory} [dirs]"
        leave_broot: false
}

here I've used square brakets to indicate a list of arguments compared to 1 argument as an example.
In this case mkmuldirs would be a simple script - something like:

#!/bin/bash


dir="$1"
shift

for var in "$@"
do
    mkdir -p "$dir/$var"
done

from broot.

CabalCrow avatar CabalCrow commented on June 4, 2024

This approach does still have 1 issue though - you are unable to use " for arguments in this case, since broot is automatically managing ".

I guess a better issue would be to ask for a way to toggle this behaviour depending on the verb. @Canop Should I open a new issue for that or can we reuse this one since it is related?

from broot.

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.