shell-functools icon indicating copy to clipboard operation
shell-functools copied to clipboard

Offering: Update the `run` function to allow for command line arguments

Open jdhedden opened this issue 2 years ago • 1 comments

The run function currently only works a single word, so trying to use command line argument with a command doesn't work (e.g., 'chmod 755'). The version adds that capability:

@register("run")
@typed(T_ARRAY, T_VOID)
def run(command, inp):
    command = dynamic_cast(T_STRING, command).value.split()
    args = map(T_STRING.create_from, inp)
    args = list(map(lambda v: v.value, args))

    print("Running '{}' with arguments {}".format(command, args))
    subprocess.call(command + args)

For README.md:

### Usage of `run`

The `run` *function* executes a command over arguments presented:

/usr/bin/ls -1 ft/ft/*.py | map run 'chmod 644' Running '['chmod', '644']' with arguments ['ft/ft/command.py'] Running '['chmod', '644']' with arguments ['ft/ft/error.py'] Running '['chmod', '644']' with arguments ['ft/ft/functions.py'] Running '['chmod', '644']' with arguments ['ft/ft/init.py'] Running '['chmod', '644']' with arguments ['ft/ft/internal.py'] Running '['chmod', '644']' with arguments ['ft/ft/termcolor.py'] Running '['chmod', '644']' with arguments ['ft/ft/test_command.py'] Running '['chmod', '644']' with arguments ['ft/ft/types.py'] Running '['chmod', '644']' with arguments ['ft/ft/version.py']

jdhedden avatar May 09 '22 19:05 jdhedden

Thanks. Please see the other tickets regarding the maintenance status of this project.

sharkdp avatar May 22 '22 09:05 sharkdp