From f6a50923c2e7f326ab9c788e81fa71b544cc1add Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 22 Feb 2024 07:32:37 -1000 Subject: [PATCH] imp: interpret glob patterns in $LEDGER_FILE For example, LEDGER_FILE=2???.journal now works. --- hledger-lib/Hledger/Read.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hledger-lib/Hledger/Read.hs b/hledger-lib/Hledger/Read.hs index ea96b7547..967bc2293 100644 --- a/hledger-lib/Hledger/Read.hs +++ b/hledger-lib/Hledger/Read.hs @@ -140,7 +140,7 @@ import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.IO as T import Data.Time (Day) -import Safe (headDef) +import Safe (headDef, headMay) import System.Directory (doesFileExist, getHomeDirectory) import System.Environment (getEnv) import System.Exit (exitFailure) @@ -184,8 +184,12 @@ defaultJournal = defaultJournalPath >>= runExceptT . readJournalFile definputopt -- determine a home directory). defaultJournalPath :: IO String defaultJournalPath = do - s <- envJournalPath - if null s then defpath else return s + p <- envJournalPath + if null p + then defpath + else do + ps <- expandGlob "." p `C.catch` (\(_::C.IOException) -> return []) + maybe defpath return $ headMay ps where envJournalPath = getEnv journalEnvVar