git.iko.soy/typeable/pandoc
on master help sign in
Fix bash completion for `--print-default-data-file`.

Previously this looked in the filesystem, even if pandoc was compiled with `embed_data_files` (and sometimes it looked in a nonexistent build directory). Now the bash completion script just includes a hard-coded list of data file names. See #4549.

commit499c91dd9698c15bac2667a90b2b3ddc1a0f1930 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 12 Apr 2018, 09:50 (9 years ago) parentc3d0cc9
2 files changed+19−5
data/bash_completion.tpl+3−3 src/Text/Pandoc/App.hs+16−2
data/bash_completion.tpl+3−3
@@ -4,7 +4,7 @@
44
55_pandoc()
66{
7− local cur prev opts lastc informats outformats datadir
7+ local cur prev opts lastc informats outformats datafiles
88 COMPREPLY=()
99 cur="${COMP_WORDS[COMP_CWORD]}"
1010 prev="${COMP_WORDS[COMP_CWORD-1]}"
@@ -14,7 +14,7 @@ _pandoc()
1414 informats="%s"
1515 outformats="%s"
1616 highlight_styles="%s"
17− datadir="%s"
17+ datafiles="%s"
1818
1919 case "${prev}" in
2020 --from|-f|--read|-r)
@@ -34,7 +34,7 @@ _pandoc()
3434 return 0
3535 ;;
3636 --print-default-data-file)
37− COMPREPLY=( $(compgen -W "reference.odt reference.docx $(find ${datadir} | sed -e 's/.*\/data\///')" -- ${cur}) )
37+ COMPREPLY=( $(compgen -W "${datafiles}" -- ${cur}) )
3838 return 0
3939 ;;
4040 --wrap)
src/Text/Pandoc/App.hs+16−2
@@ -66,7 +66,11 @@ import Data.Yaml (decode)
6666import qualified Data.Yaml as Yaml
6767import GHC.Generics
6868import Network.URI (URI (..), parseURI)
69+#ifdef EMBED_DATA_FILES
70+import Text.Pandoc.Data (dataFiles)
71+#else
6972import Paths_pandoc (getDataDir)
73+#endif
7074import Data.Aeson.Encode.Pretty (encodePretty', Config(..), keyOrder,
7175 defConfig, Indent(..), NumberFormat(..))
7276import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme,
@@ -1475,7 +1479,7 @@ options =
14751479 , Option "" ["bash-completion"]
14761480 (NoArg
14771481 (\_ -> do
1478− ddir <- getDataDir
1482+ datafiles <- getDataFileNames
14791483 tpl <- runIOorExplode $
14801484 UTF8.toString <$>
14811485 readDefaultDataFile "bash_completion.tpl"
@@ -1487,7 +1491,7 @@ options =
14871491 (unwords readersNames)
14881492 (unwords writersNames)
14891493 (unwords $ map fst highlightingStyles)
1490− ddir
1494+ (unwords datafiles)
14911495 exitSuccess ))
14921496 "" -- "Print bash completion script"
14931497
@@ -1561,6 +1565,16 @@ options =
15611565
15621566 ]
15631567
1568+getDataFileNames :: IO [FilePath]
1569+getDataFileNames = do
1570+#ifdef EMBED_DATA_FILES
1571+ let allDataFiles = map fst dataFiles
1572+#else
1573+ allDataFiles <- filter (\x -> x /= "." && x /= "..") <$>
1574+ (getDataDir >>= getDirectoryContents)
1575+#endif
1576+ return $ "reference.docx" : "reference.odt" : "reference.pptx" : allDataFiles
1577+
15641578-- Returns usage message
15651579usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
15661580usageMessage programName = usageInfo (programName ++ " [OPTIONS] [FILES]")