:write_stdout and :writeln_stdout internals
The :writeln_stdout internal allows recreating the :print_path verb:
{
invocation: pp
cmd: ":write_stdout {file};:quit"
}
but it's more generic.
With the :write_stdout, you can for example write the path without the trailing newline:
{
invocation: wp
cmd: ":writeln_stdout {file};:quit"
}
These are the verbs I tested against
{
invocation: "echo_stdout_quit"
external: "echo {file}"
from_shell: true
}
{
invocation: "test_stdout_quit"
cmd: ":write_stdout {file};:quit"
}
{
invocation: "testln_stdout_quit"
cmd: ":writeln_stdout {file};:quit"
}
{
invocation: "test_stdout"
cmd: ":write_stdout {file}"
}
{
invocation: "testln_stdout"
cmd: ":writeln_stdout {file}"
}
I'm seeing a few oddities here.
In no particular order:
- Should
write_stdoutandwriteln_stdoutbe callable from within broot? They don't accomplish much outside of verb use. - Is this new? It's preventing use of @Alfamari 's previously working
echo {file}from shell. - In the staging area, the four
test*verbs don't trigger the above error, but they also simply aren't found if more than one file is staged. - Staging area would be preferred, since it allows the user to see what they have done, and allows for correcting mistakes. However, via
testln_stdoutit is possible to accumulate files on stdout. Unfortunately this smacks us right into the original problem from #888 : there's a newline at the end of the list. Note: I reverted my changes in br.ps1 to test this PR. - With
test_stdout_quitit is possible to pass one file to powershell.But of course, multiple invocations of
test_stdoutwon't help with further files.I do see a workaround - calling
testln_stdoutfor some files, andtest_stdout_quiton the last file. I don't know that this qualifies as a solution though. - This might be an unrelated bug, but in the course of testing these verbs some dozen times I noticed that tab complete happily cycles through all four verbs with
test<tab>, buttestln<tab>autocompletes totestln_stdout_quitand will not cycle with the other matchtestln_stdout. 🤷
In summary, write_stdout and writeln_stdout narrowly avoid solving the problem :)
write_stdoutonly supports passing one filewriteln_stdoutalways contains a problematic newline- Neither are available in the staging area
As a final thought - in addition to text output, it might be worth supporting json output, too. That's a trendy thing to do these days, and would play quite nicely with object oriented shells like powershell. Or any shell could leverage something like jq.
A lot of good point. Also https://github.com/Canop/broot/issues/888#issuecomment-2224324287
An approach might be to allow more settings to be carried by verb arguments, using the syntax I introduced at https://github.com/Canop/broot/blob/main/CHANGELOG.md#v091---2019-07-29
This could for example be write_stdout {file:comma-separated};:quit or write_stdout {directory:json-array} or write_stdout {directory:lines}.
I'll be cautious though, as I don't want to be carried into introducing user-side complexity solving only one problem.
I'm dropping this PR and will try another approach.