diff --git a/bin/README.md b/bin/README.md index e469bc01a..6945ea829 100644 --- a/bin/README.md +++ b/bin/README.md @@ -366,20 +366,6 @@ It has the same structure as most of the add-ons here: - providing command line help - accepting common hledger options -### hledger-print-location - -[`hledger-print-location.hs`](https://github.com/simonmichael/hledger/blob/master/bin/hledger-print-location.hs) -is a variant of hledger's `print` command -that adds the file and line number to every transaction, as a tag: -```cli -$ hledger print-location -f hledger/examples/sample.journal desc:eat -2008/06/03 * eat & shop - ; location: /Users/simon/src/hledger/examples/sample.journal:30 - expenses:food $1 - expenses:supplies $1 - assets:cash -``` - ### hledger-swap-dates [`hledger-swap-dates.hs`](https://github.com/simonmichael/hledger/blob/master/bin/hledger-swap-dates.hs) diff --git a/bin/hledger-print-location.hs b/bin/hledger-print-location.hs deleted file mode 100755 index 780c742e5..000000000 --- a/bin/hledger-print-location.hs +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env stack --- stack runghc --verbosity info --package hledger --package string-qq --- Run from inside the hledger source tree, or compile with compile.sh. --- See hledger-check-fancyassertions.hs. - -{- -Quick script that adds file/line number tags to print output. -cf https://www.reddit.com/r/plaintextaccounting/comments/ddzn8o/finding_corresponding_journal_files_from_hledger/ - -$ hledger print-location -f examples/sample.journal desc:eat -2008/06/03 * eat & shop - ; location: /Users/simon/src/hledger/examples/sample.journal:30 - expenses:food $1 - expenses:supplies $1 - assets:cash --} - -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE QuasiQuotes #-} - -import Data.String.QQ (s) -import qualified Data.Text as T -import Hledger.Cli.Script - ------------------------------------------------------------------------------- -cmdmode = hledgerCommandMode - [s| print-location -Like print, but adds tags showing the file path and location of transactions. - |] - [] - [generalflagsgroup1] - [] - ([], Just $ argsFlag "[QUERY]") ------------------------------------------------------------------------------- - -main :: IO () -main = do - opts <- getHledgerCliOpts cmdmode - withJournalDo opts $ \j -> - print' opts j{jtxns = map addLocationTag $ jtxns j} - -addLocationTag :: Transaction -> Transaction -addLocationTag t = t{tcomment = tcomment t `commentAddTagNextLine` loctag} - where - loctag = ("location", T.pack . sourcePosPairPretty $ tsourcepos t) - --- Like showSourcePosPair in Hledger.Data.Transaction, but show just the starting line number. -showSourcePosPairLine :: (SourcePos, SourcePos) -> String -showSourcePosPairLine (SourcePos f line _, _) = f ++ ":" ++ show line diff --git a/hledger/Hledger/Cli/Commands/Print.hs b/hledger/Hledger/Cli/Commands/Print.hs index eab9c574e..153a06a82 100644 --- a/hledger/Hledger/Cli/Commands/Print.hs +++ b/hledger/Hledger/Cli/Commands/Print.hs @@ -60,7 +60,7 @@ printmode = hledgerCommandMode flagReq ["match","m"] (\s opts -> Right $ setopt "match" s opts) arg ("fuzzy search for one recent transaction with description closest to "++arg) ,flagReq ["base-url"] (\s opts -> Right $ setopt "base-url" s opts) "URLPREFIX" "in html output, generate links to hledger-web, with this prefix. (Usually the base url shown by hledger-web; can also be relative.)" - ,flagNone ["l", "location"] (setboolopt "location") "add file/line number tags to print output" + ,flagNone ["location"] (setboolopt "location") "add file/line number tags to print output" ,outputFormatFlag ["txt","beancount","csv","tsv","html","fods","json","sql"] ,outputFileFlag ]) @@ -366,7 +366,6 @@ postingToSpreadsheet fmt baseUrl query p = account = showAccountName Nothing (ptype p) (paccount p) comment = T.strip $ pcomment p --- from hledger/bin/hledger-print-location.hs addLocationTag :: Transaction -> Transaction addLocationTag t = t{tcomment = tcomment t `commentAddTagNextLine` loctag} where diff --git a/hledger/Hledger/Cli/Commands/Print.md b/hledger/Hledger/Cli/Commands/Print.md index 1dd3c4ffa..a037934ab 100644 --- a/hledger/Hledger/Cli/Commands/Print.md +++ b/hledger/Hledger/Cli/Commands/Print.md @@ -29,7 +29,7 @@ Flags: txt, beancount, csv, tsv, html, fods, json, sql. -o --output-file=FILE write output to FILE. A file extension matching one of the above formats selects that format. - -l --location add file/line number tags to print output. + --location add file/line number tags to print output. ``` The print command displays full journal entries (transactions) @@ -139,6 +139,16 @@ DESC should contain at least two characters. If there is no similar-enough match, no transaction will be shown and the program exit code will be non-zero. +With `--location`, print adds the file and line number to every transaction, as a tag: + +```cli +$ hledger print-location -f hledger/examples/sample.journal desc:eat +2008/06/03 * eat & shop + ; location: /Users/simon/src/hledger/examples/sample.journal:30 + expenses:food $1 + expenses:supplies $1 + assets:cash +``` ### print output format