~bmp/hayom

5862425e3083416b0272c3ffa6857b73577ae992 — Benjamin Pollack 5 months ago 5c59bcb
make an explicit -j/--journal option

Having the implicit journal name was just mucking me up too much.  Axe it, and make the option explicit.

Implements: https://todo.sr.ht/~bmp/hayom/3
2 files changed, 51 insertions(+), 27 deletions(-)

M README.md
M cli.ts
M README.md => README.md +38 -16
@@ 1,8 1,15 @@
# Hayom

Hayom is a rewrite (and gradual reimagining) of [jrnl][jrnl].  As-is, it solves exactly one thing: it's not written in Python, and therefore doesn't do your choice of breaking constantly when the system Python gets changed, or having to maintain your own pyenv/virtualenv/what-have-you.
Hayom is a rewrite (and gradual reimagining) of [jrnl][jrnl]. As-is, it solves
exactly one thing: it's not written in Python, and therefore doesn't do your
choice of breaking constantly when the system Python gets changed, or having to
maintain your own pyenv/virtualenv/what-have-you.

The file format of Hayom is identical to jrnl, so it's easy to point both tools to the same file if you wish (at least for now) and use them interchangeably.  Over time, this likely will change in a subtle and fairly backwards-compatible way, for the basic reason that I want a blank line between the entry title and the entry body.  But for now, you're golden.
The file format of Hayom is identical to jrnl, so it's easy to point both tools
to the same file if you wish (at least for now) and use them interchangeably.
Over time, this likely will change in a subtle and fairly backwards-compatible
way, for the basic reason that I want a blank line between the entry title and
the entry body. But for now, you're golden.

## Installation



@@ 11,25 18,33 @@ The file format of Hayom is identical to jrnl, so it's easy to point both tools 

## Usage

Writing entries with Hayom is designed to be as easy as possible so there is no friction.  For short entries, it's trivial to just write it right on the command line:
Writing entries with Hayom is designed to be as easy as possible so there is no
friction. For short entries, it's trivial to just write it right on the command
line:

    hayom Today, I ate some pancakes. They were delicious.

Everything up to the end of the first sentence will be considered the entry title. It's fine to have just a title.
Everything up to the end of the first sentence will be considered the entry
title. It's fine to have just a title.

For longer entries, just type `hayom`, and it'll pop up an editor.  Hayom will honor the `editor` setting in its config file first, `$EDITOR` second, and attempt to use `nano` last.
For longer entries, just type `hayom`, and it'll pop up an editor. Hayom will
honor the `editor` setting in its config file first, `$EDITOR` second, and
attempt to use `nano` last.

To read entries, you must specify any of the filtering commands.  These commands are:
To read entries, you must specify any of the filtering commands. These commands
are:

 * `--from`/`-f`: the earliest timestamp to include
 * `--to`/`-t`: the last timestamp to include
 * `--summary`/`-s`: show just entry titles, not bodies
 * `--count`/`-n`: how many entries to show
 * `--on`: show entries made on a specific day
- `--from`/`-f`: the earliest timestamp to include
- `--to`/`-t`: the last timestamp to include
- `--summary`/`-s`: show just entry titles, not bodies
- `--count`/`-n`: how many entries to show
- `--on`: show entries made on a specific day

You can additionally specify tags (formatted as `@tagname`) to filter entries.

All of the time based commands take natural English, not just dates.  For example, this gives you all the entries between last month and this month that were about `@bob`'s `@tpsreport`:
All of the time based commands take natural English, not just dates. For
example, this gives you all the entries between last month and this month that
were about `@bob`'s `@tpsreport`:

    hayom -f '2 months ago' -t 'this month' @bob @tpsreport



@@ 39,14 54,21 @@ Or, if you're curious what you did last Tuesday, it's as easy as writing:

## Multiple Journals

You can have multiple journals.  If you do, the *very first* word on the command line will specify the journal to use, and does *not* need to be done as a command format.  For example, if I have a journal called `work` and a journal called `personal`, I might do
You can have multiple journals. If you do, simply specify the journal you want
with the `--journal` or `-j` command. E.g., if you had `personal` and `work`
journals, you might do

    hayom work Finally filed my stupid @tpsreport
    hayom personal Sent out a pile of résumés today
    hayom -j work Finally filed my stupid @tpsreport
    hayom -j personal Sent out a pile of résumés today

If you don't specify a journal, hayom will use the default.

## Configuration

Hayom works fine with no configuration file.  If you do that, it will make a journal called `.journal` in your `$HOME`.  Alternatively, you can create a file called `$XDG_CONFIG_HOME/hayom/hayom.toml` with your configuration options.  An example configuration file might look like:
Hayom works fine with no configuration file. If you do that, it will make a
journal called `.journal` in your `$HOME`. Alternatively, you can create a file
called `$XDG_CONFIG_HOME/hayom/hayom.toml` with your configuration options. An
example configuration file might look like:

    editor = "kak"
    default = "personal"

M cli.ts => cli.ts +13 -11
@@ 66,13 66,19 @@ async function main() {
  const args = [...Deno.args];
  const config = loadConfig();

  let path;
  if (args.length > 0 && Object.hasOwn(config.journals, args[0])) {
    path = config.journals[args[0]].journal;
    args.shift();
  } else {
    path = config.journals[config.default].journal;
  }
  const opts = flags.parse(args, {
    boolean: ["summary"],
    alias: {
      "s": ["summary"],
      "f": ["from"],
      "t": ["to"],
      "n": ["count"],
      "j": ["journal"],
    },
  });

  const journal = opts.journal ?? config.default;
  const path = config.journals[journal].journal;

  try {
    Deno.lstatSync(path);


@@ 83,10 89,6 @@ async function main() {
  }

  const entries = loadEntries(path);
  const opts = flags.parse(args, {
    boolean: ["summary"],
    alias: { "s": ["summary"], "f": ["from"], "t": ["to"], "n": ["count"] },
  });

  if (
    ["from", "f", "to", "t", "on", "count", "n"].some((arg) => arg in opts) ||