Code Monkey home page Code Monkey logo

Comments (6)

simonmichael avatar simonmichael commented on September 10, 2024 1

How about (ignoring parent directories for now since this is complicated enough):

  1. use -f FILE if specified
  2. or $LEDGER_FILE if set
  3. or ./.hledger if it exists # NEW
  4. or alphanumerically first of ./THISYEAR*.{hledger,journal,ledger,j} # NEW
  5. or alphanumerically first of ./LATESTPREVYEAR*.{hledger,journal,ledger,j} # NEW
  6. or alphanumerically first of ./*.{hledger,journal,ledger,j} # NEW
  7. or $HOME/.hledger.journal

(There is a slight cost to adding a top-level including file: the top-level AKA primary file gets some special treatment, like being the default target for add and hledger-web add form. .hledger could also be a symlink, avoiding that problem.)

[Edit:

  1. use -f FILE if specified
  2. or $LEDGER_FILE if set
  3. or ./.hledger{,.EXT} if it exists. (Optional extension allows it to be any hledger format, not just journal ?) NEW
  4. or alphanumerically first of
    the latest non-future year journals (./YYYY*.{hledger,journal,ledger,j})
    or any journals (./*.{hledger,journal,ledger,j})
    (or other supported formats too ?)
    NEW
  5. or $HOME/.hledger.journal

]

from hledger.

simonmichael avatar simonmichael commented on September 10, 2024

I hear you @alerque. That's true, hledger currently prioritises ease of working with "user's journal", not a project-scoped journal. The latter is a more advanced use case for technical users, but perhaps adding more support for it would not disturb the former.

Let's not if we don't need to though. So alternatives include

  • #1013's shell one-liner that emulates config file support
  • Using a consistent journal file name across projects, and aliasing "hledger -f main.ledger" or setting LEDGER_FILE to "main.ledger"
  • Automatically setting LEDGER_FILE in project directories, using direnv or similar

It sounds like these aren't working for you because you want this feature usable by others (not just yourself) and they are all too much overhead ?

from hledger.

simonmichael avatar simonmichael commented on September 10, 2024

Brainstorming more alternatives:

  • Add the hledger command as a shebang line in project journals so they can be accessed uniformly by executing them
  • Add some heuristic to hledger that prioritises a local journal file, without configuration. Eg, use the alphabetically first (and if the file names begin with YYYY, prefer the current, otherwise the latest, year) *.hledger, *.journal, *.ledger or *.j file in the current directory or above (if LEDGER_FILE is unset ?).

from hledger.

alerque avatar alerque commented on September 10, 2024

Using hledger as a shebang is an interesting idea. In fact it already works!

#!/usr/bin/env -S hledger -f

The caveat of course is that you have to set an executable bit on a data file. Given the file may import un-escaped data that gets saved via a web API it seems a bit sketchy.

My suggestion would be to have some default ledger file read from the CWD provided LEDGER_FILE is not set. This wouldn't need to be variable like an alphabetical first match, just a fixed name that could serve as a place to import other files if necessary: default.hledger or .hledger or something of that nature... that could be excused in a non-english project where the actual data file might have a different name and is just pulled in via include real_main_file.ledger or whatever.

from hledger.

simonmichael avatar simonmichael commented on September 10, 2024

from hledger.

pwseo avatar pwseo commented on September 10, 2024

I think option no. 3 is a good one: one can always symlink .hledger to point it to their main journal file (and in filesystems with no support for symlinks, a simple include main.journal would suffice).

While all the other additional options presented (4..7) are nice additions, they don't seem to bring as much value as option no. 3, since it largely depends on the user's journal/directory organization (eg. one can have YYYY/bank-MM.journal files, easily). They're an interesting addition, I'm just not sure they're actually worth the effort at this stage.

from hledger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.