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.
This commit is contained in:
parent
c3d0cc9b8e
commit
499c91dd96
2 changed files with 19 additions and 5 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
_pandoc()
|
||||
{
|
||||
local cur prev opts lastc informats outformats datadir
|
||||
local cur prev opts lastc informats outformats datafiles
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
|
@ -14,7 +14,7 @@ _pandoc()
|
|||
informats="%s"
|
||||
outformats="%s"
|
||||
highlight_styles="%s"
|
||||
datadir="%s"
|
||||
datafiles="%s"
|
||||
|
||||
case "${prev}" in
|
||||
--from|-f|--read|-r)
|
||||
|
@ -34,7 +34,7 @@ _pandoc()
|
|||
return 0
|
||||
;;
|
||||
--print-default-data-file)
|
||||
COMPREPLY=( $(compgen -W "reference.odt reference.docx $(find ${datadir} | sed -e 's/.*\/data\///')" -- ${cur}) )
|
||||
COMPREPLY=( $(compgen -W "${datafiles}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
--wrap)
|
||||
|
|
|
@ -66,7 +66,11 @@ import Data.Yaml (decode)
|
|||
import qualified Data.Yaml as Yaml
|
||||
import GHC.Generics
|
||||
import Network.URI (URI (..), parseURI)
|
||||
#ifdef EMBED_DATA_FILES
|
||||
import Text.Pandoc.Data (dataFiles)
|
||||
#else
|
||||
import Paths_pandoc (getDataDir)
|
||||
#endif
|
||||
import Data.Aeson.Encode.Pretty (encodePretty', Config(..), keyOrder,
|
||||
defConfig, Indent(..), NumberFormat(..))
|
||||
import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme,
|
||||
|
@ -1475,7 +1479,7 @@ options =
|
|||
, Option "" ["bash-completion"]
|
||||
(NoArg
|
||||
(\_ -> do
|
||||
ddir <- getDataDir
|
||||
datafiles <- getDataFileNames
|
||||
tpl <- runIOorExplode $
|
||||
UTF8.toString <$>
|
||||
readDefaultDataFile "bash_completion.tpl"
|
||||
|
@ -1487,7 +1491,7 @@ options =
|
|||
(unwords readersNames)
|
||||
(unwords writersNames)
|
||||
(unwords $ map fst highlightingStyles)
|
||||
ddir
|
||||
(unwords datafiles)
|
||||
exitSuccess ))
|
||||
"" -- "Print bash completion script"
|
||||
|
||||
|
@ -1561,6 +1565,16 @@ options =
|
|||
|
||||
]
|
||||
|
||||
getDataFileNames :: IO [FilePath]
|
||||
getDataFileNames = do
|
||||
#ifdef EMBED_DATA_FILES
|
||||
let allDataFiles = map fst dataFiles
|
||||
#else
|
||||
allDataFiles <- filter (\x -> x /= "." && x /= "..") <$>
|
||||
(getDataDir >>= getDirectoryContents)
|
||||
#endif
|
||||
return $ "reference.docx" : "reference.odt" : "reference.pptx" : allDataFiles
|
||||
|
||||
-- Returns usage message
|
||||
usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
|
||||
usageMessage programName = usageInfo (programName ++ " [OPTIONS] [FILES]")
|
||||
|
|
Loading…
Add table
Reference in a new issue