How do I check for tags without value?

38 views
Skip to first unread message

crea.24...@gmail.com

unread,
May 26, 2023, 4:14:31 AM5/26/23
to Ledger
If you declare tags and accounts using the --strict flag, you can add different checks in the account and tag declaration. I'm using check has_tag('tag-name') in the account declaration, and check value [== | =~] some_value in the tag declaration.

This works fine if you check for a specific tag value, but it doesn't work if you want to check for a tag without a value. check value != "" ,or check value != '' or a similar regex don't raise any warnings.

Is there a way to check if a tag has no value?

Martin Michlmayr

unread,
May 26, 2023, 4:56:40 AM5/26/23
to ledge...@googlegroups.com
* crea.24...@gmail.com <crea.24...@gmail.com> [2023-05-26 01:14]:
> This works fine if you check for a specific tag value, but it doesn't work
> if you want to check for a tag without a value. check value != "" ,or check
> value != '' or a similar regex don't raise any warnings.
>
> Is there a way to check if a tag has no value?

This works for me:

-l 'has_tag("foo")' -l 'tag("foo") !~ /./'

--
Martin Michlmayr
https://www.cyrius.com/

crea.24...@gmail.com

unread,
May 26, 2023, 10:46:02 AM5/26/23
to Ledger
Yes, it works. Thanks, Martin.
I found 19 lines with missing tag values in the first file I tried it on. If the tag is missing a value the pivot doesn't show the correct value.
I use the tags with --pivot <tag_name> on an account. Instead of adding more accounts, just add a tag and use --pivot.

If I use it when I declare an account or a tag (check), I don't have to remember to add it on the command line.

crea.24...@gmail.com

unread,
May 26, 2023, 11:32:29 AM5/26/23
to Ledger
...or maybe not. I was a bit quick there. It did not find tags without value, but it found tags without exactly one character (which was all my tags).
After a bit of fiddling I got it to work as I intended. After adding posts for some hours, the brain fog began to set in ;-).

But this seems to work if I add this to each account definition I check the tag on:

account Foo
        note The foo account
        alias bar
        check has_tag('baz')
check tag("baz") !~ /^$/
Reply all
Reply to author
Forward
0 new messages