-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow passing filename via environment variable. #22
Conversation
Instead of passing the filename on the command line it can be specified via the BEANCOUNT_FILE environment variable.
Thanks, this is a very good idea, as it is indeed tedious to have to specify the beancount file every time. One question: why the restriction to only specify one file via the environment variable? |
Yes, I'm not sure there is a good way to handle escaping all the possible characters in filenames. But I'm open to ideas.
…-------- Original Message --------
On 5/8/24 12:40 pm, Stefano Zacchiroli wrote:
Thanks, this is a very good idea, as it is indeed tedious to have to specify the beancount file every time.
One question: why the restriction to only specify one file via the environment variable?
Is it because it would be too complex to support a file separator (and hence escaping it) in there?
I think it's fine, but I'd like to understand the rationale before integrating this.
—
Reply to this email directly, [view it on GitHub](#22 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AABJSMAP572U45VKTCGNOZTZP4F5HAVCNFSM6AAAAABL7QLJY6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRYGIYTGOJZHE).
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
I mean, it's a classic escaping issue. We can pick a character as separator (e.g., a 0x20 space) and require that all spaces appearing in file names be escaped somehow (e.g., by doubling the space, or prefixing them with backslash, which would need to be escaped too). Every other weird character does not really pose a problem, it will just be up to the user how to shell-escape them properly so that they end up correctly in the environment variable. My question was more about whether it's worth the additional complexity, and I'm leaning "no" on this. Support for multiple files in the environment variable can also be added in the future with full backward compatibility, which is another argument for not doing this right away. |
That was my thinking, too. Especially since it isn't clear how often someone would want to do it, given that beancount already provides an include syntax. Maybe it is worth mentioning that as a workaround? That is, you can't specify multiple files but you can set BEANCOUNT_FILE to a single file "toplevel.beancount" that simply has lines like:
But maybe that's enough of an edge case it isn't worth cluttering up the documentation over. |
OK, I'm sold, let's go for this. Just a couple of nitpicks before merging:
|
I've made those changes. |
I've made those changes.
Awesome, thanks, it's merged now.
Do you have other changes pending? If not, I'll probably make a 0.6.1
release soon, to push this handy change to PyPI.
Cheers
|
I don't have anything planned but since I'm in beangrep mode if you had any other ideas or suggestions I could take a look and see if it is something I'm capable of.
…-------- Original Message --------
On 7/8/24 8:42 pm, Stefano Zacchiroli wrote:
> I've made those changes.
Awesome, thanks, it's merged now.
Do you have other changes pending? If not, I'll probably make a 0.6.1
release soon, to push this handy change to PyPI.
Cheers
—
Reply to this email directly, [view it on GitHub](#22 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AABJSMGCO2N4Q4MZIQA5ED3ZQIP5ZAVCNFSM6AAAAABL7QLJY6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZTGUYDQOBRGI).
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Instead of passing the filename on the command line it can be specified via the BEANCOUNT_FILE environment variable.
The motivation is: with grep having to specify the filename every time is plausible because you're going to run grep on a wide variety of files. With bean-grep (most? all?) people are only going to run bean-grep on a single file, their top-level beancount file. So having to continually specify it is a bit tedious, since in practice that argument will never change.
By allowing the filename to be passed via an environment variable we can bypass that repetition. The general idea is
you could use direnv to set BEANCOUNT_FILE when you enter your beancount directory. Or just set it globally once and for all in your shell configuration file. Then you can simply do
bean-grep -d 2024-01
bean-grep -p Lotus
bean-grep -a Vanguard -d 2024-01