Canop / broot

A new way to see and navigate directory trees : https://dystroy.org/broot
MIT License
10.39k stars 226 forks source link

:write_output & :clear_output, --verb_output #834

Closed Canop closed 5 months ago

Canop commented 5 months ago

Fix: #825

Add a --verb-output launch argument which takes a path to a file (which will be created if necessary)

Add a :write_output internal which allows adding a line to that file. No escaping is done (contrary to what happens with --outcmd).

Add a :clear_output internal which clears the file.

Here are 2 examples of verbs:

    {
        invocation: "wc {cmd}"
        execution: ":write_output wc:{cmd} {file-stem}.bro"
    }

    {
        key: alt-w
        cmd: ":clear_output;:write_output {directory};:quit"
    }

The first one is called with an input like :wc hop which appends to the output a line like wc:hop main.bro.

The second one makes the content of the output file the directory closest to the selection then quits. It could for example be used for a new version of the br shell function.

Note: Semantics isn't pretty. If you have a better idea than "output", please tell me.

AndydeCleyre commented 5 months ago

Thanks so much!

In my first tests, this seems almost working right, but for some reason the following verb does not quit broot. If I call the verb then manually quit it does seem to work as intended though.

  {
    key: alt-enter
    invocation: cd
    internal: ":write_output {directory}"
    leave_broot: true
  }
Canop commented 5 months ago

Today, internals don't even check the leave_broot setting of the verb. For most of them, quitting would be totally unexpected (think for example about "line_down", or "open_preview").

That's why my example in the PR description had an explicit :quit.

Maybe some internals could check it ?

AndydeCleyre commented 5 months ago

I've been using :print_path with leave_broot: true, but I guess leaving broot is part of that internal's behavior anyway? Haven't tried it with false...

OK yeah I'll make it a cmd with quit, thanks!

AndydeCleyre commented 5 months ago

Maybe an interesting quoting issue?

  {
    key: alt-enter
    invocation: cd
    cmd: ":write_output {directory};:quit"
  }

No verb matches "quit\""

Canop commented 5 months ago

This works for me

AndydeCleyre commented 5 months ago

Oh, I tried to use it on a folder named

with " a quote and spaces

AndydeCleyre commented 5 months ago

Also happens with a folder named just sp ac

Canop commented 5 months ago

Ok... I suspected there was a bug in sequence interpolation... back to draft mode!

Canop commented 5 months ago

@AndydeCleyre back to testable

AndydeCleyre commented 5 months ago

This seems to be working great with my weird folder names, thanks!

Canop commented 5 months ago

Thanks @AndydeCleyre for the review