Added --bash-completion
option.
This generates a bash completion script. To use: eval "$(pandoc --bash-completion)"
This commit is contained in:
parent
397c18810e
commit
73824908aa
4 changed files with 89 additions and 1 deletions
7
README
7
README
|
@ -250,6 +250,13 @@ General options
|
|||
`epub.css`, `templates`, `slidy`, `slideous`, or `s5` directory
|
||||
placed in this directory will override pandoc's normal defaults.
|
||||
|
||||
`--bash-completiion`
|
||||
|
||||
: Generate a bash completion script. to enable bash completion
|
||||
with pandoc, add this to your `.bashrc`:
|
||||
|
||||
eval "$(pandoc --bash-completion)"
|
||||
|
||||
`--verbose`
|
||||
|
||||
: Give verbose debugging output. Currently this only has an effect
|
||||
|
|
62
data/bash_completion.tpl
Normal file
62
data/bash_completion.tpl
Normal file
|
@ -0,0 +1,62 @@
|
|||
#!/bin/bash
|
||||
|
||||
# This script enables bash autocompletion for pandoc. To enable
|
||||
# bash completion, add this to your .bashrc:
|
||||
# eval "$(pandoc --bash-completion)"
|
||||
|
||||
_pandoc()
|
||||
{
|
||||
local cur prev opts lastc informats outformats datadir
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
|
||||
# These should be filled in by pandoc:
|
||||
opts="%s"
|
||||
informats="%s"
|
||||
outformats="%s"
|
||||
datadir="%s"
|
||||
|
||||
case "${prev}" in
|
||||
--from|-f|--read|-r)
|
||||
COMPREPLY=( $(compgen -W "${informats}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
--to|-t|--write|-w|-D|--print-default-template)
|
||||
COMPREPLY=( $(compgen -W "${outformats}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
--email-obfuscation)
|
||||
COMPREPLY=( $(compgen -W "references javascript none" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
--latex-engine)
|
||||
COMPREPLY=( $(compgen -W "pdflatex lualatex xelatex" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
--print-default-data-file)
|
||||
COMPREPLY=( $(compgen -W "reference.odt reference.docx $(find ${datadir} | sed -e 's/.*\/data\///')" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
--highlight-style)
|
||||
COMPREPLY=( $(compgen -W "pygments tango espresso zenburn kate monochrome haddock" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
case "${cur}" in
|
||||
-*)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=( $(compgen -f ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
complete -F _pandoc pandoc
|
|
@ -105,6 +105,8 @@ Data-Files:
|
|||
data/dzslides/template.html
|
||||
-- sample lua custom writer
|
||||
data/sample.lua
|
||||
-- bash completion template
|
||||
data/bash_completion.tpl
|
||||
-- documentation
|
||||
README, COPYRIGHT
|
||||
Extra-Source-Files:
|
||||
|
|
19
pandoc.hs
19
pandoc.hs
|
@ -71,7 +71,8 @@ import qualified Data.Text as T
|
|||
import Control.Applicative ((<$>), (<|>))
|
||||
import Text.Pandoc.Readers.Txt2Tags (getT2TMeta)
|
||||
import Data.Monoid
|
||||
|
||||
import Paths_pandoc (getDataDir)
|
||||
import Text.Printf (printf)
|
||||
import Text.Pandoc.Error
|
||||
|
||||
type Transform = Pandoc -> Pandoc
|
||||
|
@ -880,6 +881,22 @@ options =
|
|||
(\opt -> return opt { optVerbose = True }))
|
||||
"" -- "Verbose diagnostic output."
|
||||
|
||||
, Option "" ["bash-completion"]
|
||||
(NoArg
|
||||
(\_ -> do
|
||||
ddir <- getDataDir
|
||||
tpl <- readDataFileUTF8 Nothing "bash_completion.tpl"
|
||||
let optnames (Option shorts longs _ _) =
|
||||
map (\c -> ['-',c]) shorts ++
|
||||
map ("--" ++) longs
|
||||
let allopts = unwords (concatMap optnames options)
|
||||
UTF8.hPutStrLn stdout $ printf tpl allopts
|
||||
(unwords (map fst readers))
|
||||
(unwords ("pdf": map fst writers))
|
||||
ddir
|
||||
exitWith ExitSuccess ))
|
||||
"" -- "Print bash completion script"
|
||||
|
||||
, Option "v" ["version"]
|
||||
(NoArg
|
||||
(\_ -> do
|
||||
|
|
Loading…
Add table
Reference in a new issue