scripts: uniquify
This commit is contained in:
parent
559d7ba2c9
commit
bc8411219b
21
examples/uniquify.hs
Normal file
21
examples/uniquify.hs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env runhaskell
|
||||||
|
{-|
|
||||||
|
Uniquify journal entries based on some id in the description. Reads the
|
||||||
|
default or specified journal, or stdin.
|
||||||
|
|
||||||
|
Usage: uniquify.hs [-f JOURNALFILE | -f-]
|
||||||
|
|-}
|
||||||
|
|
||||||
|
import Data.List
|
||||||
|
import Hledger
|
||||||
|
import Hledger.Cli
|
||||||
|
|
||||||
|
main = do
|
||||||
|
opts <- getHledgerOpts
|
||||||
|
withJournalDo opts uniquifyAndPrint
|
||||||
|
|
||||||
|
uniquifyAndPrint :: CliOpts -> Journal -> IO ()
|
||||||
|
uniquifyAndPrint opts j@Journal{jtxns=ts} = print' opts j{jtxns=uniquify ts}
|
||||||
|
where
|
||||||
|
uniquify = nubBy (\t1 t2 -> extractId (tdescription t1) == extractId (tdescription t2))
|
||||||
|
extractId desc = desc -- extract some part that's supposed to be unique
|
||||||
Loading…
Reference in New Issue
Block a user