Copy-pasting multiline (multiple lines) query into bean-query

103 views
Skip to first unread message

Dan Andersson

unread,
Feb 10, 2024, 9:24:32 AM2/10/24
to Beancount
Hi,

After doing bean-query foo.beancount to enter the interactive session, can I somehow copy-paste multiple lines in there?

It seems like multi-line queries (e.g. the examples in the documentation), when pasted in there, always get split into one command per line, resulting in errors.

Do I always have to combine those lines first, before pasting them?

Thanks,
DA

Martin Blais

unread,
Feb 10, 2024, 10:01:39 AM2/10/24
to bean...@googlegroups.com
This is a bash question. Look at how multiple lines are handled in bash (should be lots of info online).

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/50b1d037-b464-4838-ae46-58ffc250e8b8n%40googlegroups.com.

Dan Andersson

unread,
Feb 13, 2024, 5:51:12 AM2/13/24
to Beancount
Hi, I'm aware that backslashes can be used for Bash.
I was referring to the interactive session (after doing only "bean-query foo.beancount"). I guess I was hoping it wouldn't "complete" a command until it sees a semicolon, but currently it seems to complete a command after every newline.

Dan Andersson

unread,
Feb 13, 2024, 5:55:06 AM2/13/24
to Beancount
Motivation: Give people (including Windows users) copy-pasteable commands they can simply use as-is (regardless of platform).

Martin Blais

unread,
Feb 14, 2024, 9:32:07 PM2/14/24
to bean...@googlegroups.com
I don't know. If it's supported in https://docs.python.org/3/library/cmd.html it should be possible to improve it.


Robert Hotchkiss

unread,
Feb 15, 2024, 7:08:19 PM2/15/24
to bean...@googlegroups.com
I was not able to figure out how to do multi-line queries in interactive bean-query so I paste them into my beancount file and use fava to run them or run them with:

> bean-query <beancount file> run <query-name>

I did jot this down in my notes, but not sure if my notes are accurate:

- bean-query interactive uses the python gnu readline package (not to be confused with python library's readline)
   - https://stackoverflow.com/questions/161495/is-there-a-nice-way-of-handling-multi-line-input-with-gnu-readline
   - https://pymotw.com/2/readline/




--

Daniele Nicolodi

unread,
Feb 16, 2024, 9:13:01 AM2/16/24
to bean...@googlegroups.com
On 16/02/24 01:08, Robert Hotchkiss wrote:
> I did jot this down in my notes, but not sure if my notes are accurate:
>
> - bean-query interactive uses the python gnu readline package (not to be
> confused with python library's readline)
>    - https://stackoverflow.com/questions/161495/is-there-a-nice-way-of-handling-multi-line-input-with-gnu-readline
>    - https://pymotw.com/2/readline/

This is not accurate: bean-query uses the readline Python standard
library module, which uses GNU readline on Linux, libedit on macOS, and
is not available on Window.

Cheers,
Dan

Daniele Nicolodi

unread,
Feb 16, 2024, 9:19:14 AM2/16/24
to bean...@googlegroups.com
Multi-line input is not currently supported by bean-query. The
interactive interpreter is based on the cmd Python standard library
module, which is a line based command interpreter.

Using a semicolon as query terminator instead of a newline should be
possible (the Python REPL supports multi-line input statements, thus the
functionality is there, somewhere) but it would require moving from a
very simple REPL to something that uses a much more fancy parser.

I had investigating this on my TODO list for a long time, but I haven't
had the time to look into it yet.

Cheers,
Dan

Reply all
Reply to author
Forward
0 new messages