From 6859b94f4b6daaa3b010ba36a83ba128bf14f744 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 24 Jan 2017 19:31:57 -0800 Subject: [PATCH] cli: omit source addons from list when compiled version is present, again Source and compiled versions of all addons in bin are cluttering up the commands list. I think this was reasonably well behaved, so I'm re-enabling it, possibly with a slight fix (.c shadowing .exe). Some notes: - when there's only one addon with its base filename, its extension is not displayed (as before) - addons with (case insensitive) .exe extension or no extension are considered compiled - when there's exactly two addons with the same base filename, and one of them looks compiled, only that one is kept - modification time is not checked; an old compiled addon overrides a newer source version - when there's more than two addons with same base filename, all are kept --- hledger/Hledger/Cli/CliOptions.hs | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/hledger/Hledger/Cli/CliOptions.hs b/hledger/Hledger/Cli/CliOptions.hs index 45197ddd0..222acd219 100644 --- a/hledger/Hledger/Cli/CliOptions.hs +++ b/hledger/Hledger/Cli/CliOptions.hs @@ -552,34 +552,34 @@ defaultBalanceLineFormat = BottomAligned [ -- Other utils -- | Get the sorted unique precise names and display names of hledger --- add-ons found in the current user's PATH. The precise names are the --- add-on's filename with the "hledger-" prefix removed. The display --- names have the file extension removed also, except when it's needed --- for disambiguation. --- --- -- Also when there are exactly two similar names, one with the .hs or --- -- .lhs extension and the other with the .exe extension or no --- -- extension - presumably source and compiled versions of a haskell --- -- script - we exclude the source version. --- --- This function can return add-on names which shadow built-in command --- names, but hledger will ignore these. +-- add-on executables found in the current user's PATH. +-- Precise names are the file names with the "hledger-" prefix removed. +-- Display names also have the file extension removed, except when it's +-- needed to disambiguate multiple add-ons with similar filenames. +-- When there are exactly two similar names that look like a source +-- and compiled version (.exe, .com, or no extension), the source +-- version is excluded (even if it happens to be newer). +-- Add-on names matching built-in command names could be returned +-- by this function, though hledger will ignore them. -- hledgerAddons :: IO ([String],[String]) hledgerAddons = do exes <- hledgerExecutablesInPath - let precisenames = -- concatMap dropRedundant $ - -- groupBy (\a b -> dropExtension a == dropExtension b) $ + let precisenames = concatMap dropRedundant $ + groupBy (\a b -> dropExtension a == dropExtension b) $ map stripprefix exes let displaynames = concatMap stripext $ groupBy (\a b -> dropExtension a == dropExtension b) precisenames return (precisenames, displaynames) where stripprefix = drop (length progname + 1) - -- dropRedundant [f,f2] | takeExtension f `elem` ["",".exe"] && takeExtension f2 `elem` [".hs",".lhs"] = [f] - -- dropRedundant fs = fs stripext [f] = [dropExtension f] stripext fs = fs + compiledExts = ["",".com",".exe"] + dropRedundant [f,g] + | takeExtension f `elem` compiledExts = [f] + | takeExtension g `elem` compiledExts = [g] + dropRedundant fs = fs -- | Get the sorted unique filenames of all hledger-* executables in -- the current user's PATH. Currently these are: files in any of the