App-orgsel

 view release on metacpan or  search on metacpan

script/orgsel  view on Meta::CPAN

 % orgsel todo.org 'Headline[level=2][title.as_string =~ /eats comments/]' | dump-org-structure

 # show the update log of the todo item (with the "- log ::"):
 % orgsel todo.org 'Headline[level=2][title.as_string =~ /eats comments/] > List > ListItem[desc_term.text = "log"]:parent'

 # show the update log of the todo item (without the "- log ::"):
 % orgsel todo.org 'Headline[level=2][title.as_string =~ /eats comments/] > List > ListItem[desc_term.text = "log"] + *'

 # select todo items which have been updated at least twice (by looking at
 # number of list items under "log")
 % orgsel todo.org 'Headline[level=2] > List > ListItem[desc_term.text = "log"] + *:has-min-children(2):parent:parent'

=head2 Examples using F<addressbook.org>

Example document F<addressbook.org> (you can get this from the distribution
shared file):

 #+TODO: TODO | OLD
 
 * business > tax consultants
 * business > veterinarian
 ** budi chandra                                                         :vet:
 - born :: 1981?
 - notes ::
   + moslem
   + has two kids, the older is 10yo @2012
 - address :: jl anggrek no 123, bandung
 - opening hours :: every day 07-21, also on call 24h
 - phone :: 0855 555 1234
 - log ::
   + [2012-07-30 ] dr went to our house to vaccinate bonnie
   + [2010-04-21 ] went to his clinic, bought worm tablets
 ** deni setiawan                                                        :vet:
 - notes ::
   + day-care for dogs etc at his house, but there is concern about ticks
 - address :: jl mawar 456, bandung
 - phone :: 022 5551235
 - log ::
   + [2013-09-18 Rab] entry
 * family tree > dad's side
 ** budi roland                                                     :deceased:
 ** grace shanti
 - notes ::
   + father's first aunt
   + 85 yo @2021
 - log ::
   + [2021-06-26] entry
 * family tree > mom's side
 * zzz > old
 ** OLD rudi sanusi
 - phone/whatsapp :: 0855 555 9739
 - log ::
   + [2021-06-27 Sun] mark as old
 * zzz > unorganized
 ** agus (lisa's husband)
 ** agus putra
 ** susan muliawati
 ** susi
 ** susi (ron's friend)                                                  :vet:
 - log ::
   + [2021-04-03] met her again (the 3rd time i guess?) at ron's birthday party.
     she's married now.
   + [2019-01-02] entry

Now for some selecting examples on F<addressbook.org>:

 # list contacts which have certain tag ("vet")
 % orgsel addressbook.org 'Headline[level=2][tags has "vet"]' --eval 'say $_->title->as_string'

 # count contacts matching /budi (and list them as well)
 % orgsel addressbook.org 'Headline[level=2][title.as_string =~ /budi/i]'  --eval 'say $_->title->as_string' --count

 # show notes about contact 'deni setiawan'
 % orgsel addressbook.org 'Headline[level=2][title.as_string = "deni setiawan"] > List > ListItem[desc_term.text = "notes"] + *'

=head1 DESCRIPTION

This utility allows you to select nodes from Org document on the command-line
using CSel selector syntax.

Org is a plain-text document format for keeping notes, maintaining to-do lists,
planning projects, authoring documents, and more. The specification and official
documentation is at L<https://orgmode.org>.

CSel is a pattern syntax to select various elements from a tree. It is modeled
after CSS selector. The specification is at L<Data::CSel>.

In B<orgsel>, Org document is first parsed into a document tree using
L<Org::Parser> then selected with the given CSel expression. Types are
C<Org::Element::*> classes (without the prefix).

See examples in the Synopsis to get an idea on how to use B<orgsel>.

Some tips:

=over

=item * To find out which attributes (methods) available for selecting using attribute selector, see documentation on C<Org::Element::*>

=back

=head1 OPTIONS

C<*> marks required options.

=head2 Main options

=over

=item B<--count>

Shortcut for --node-action count.

See C<--node-action>.

=item B<--dump>

Shortcut for --node-action dump.

See C<--node-action>.



( run in 0.677 second using v1.01-cache-2.11-cpan-39bf76dae61 )