Skip to content

Commit f6a5092

Browse files
committed
imp: interpret glob patterns in $LEDGER_FILE
For example, LEDGER_FILE=2???.journal now works.
1 parent e6b3fa0 commit f6a5092

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

hledger-lib/Hledger/Read.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ import Data.Text (Text)
140140
import qualified Data.Text as T
141141
import qualified Data.Text.IO as T
142142
import Data.Time (Day)
143-
import Safe (headDef)
143+
import Safe (headDef, headMay)
144144
import System.Directory (doesFileExist, getHomeDirectory)
145145
import System.Environment (getEnv)
146146
import System.Exit (exitFailure)
@@ -184,8 +184,12 @@ defaultJournal = defaultJournalPath >>= runExceptT . readJournalFile definputopt
184184
-- determine a home directory).
185185
defaultJournalPath :: IO String
186186
defaultJournalPath = do
187-
s <- envJournalPath
188-
if null s then defpath else return s
187+
p <- envJournalPath
188+
if null p
189+
then defpath
190+
else do
191+
ps <- expandGlob "." p `C.catch` (\(_::C.IOException) -> return [])
192+
maybe defpath return $ headMay ps
189193
where
190194
envJournalPath =
191195
getEnv journalEnvVar

0 commit comments

Comments
 (0)