git.iko.soy/typeable/pandoc
on master help sign in
Added `--bash-completion` option.

This generates a bash completion script. To use: eval "$(pandoc --bash-completion)"

commit73824908aab1d910996cf4db7baf722aecc32d31 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 13 Aug 2015, 15:24 (11 years ago) parent397c188
4 files changed+89−1
README+7 data/bash_completion.tpl+62 pandoc.cabal+2 pandoc.hs+18−1
README+7
@@ -250,6 +250,13 @@ General options
250250 `epub.css`, `templates`, `slidy`, `slideous`, or `s5` directory
251251 placed in this directory will override pandoc's normal defaults.
252252
253+`--bash-completiion`
254+
255+: Generate a bash completion script. to enable bash completion
256+ with pandoc, add this to your `.bashrc`:
257+
258+ eval "$(pandoc --bash-completion)"
259+
253260`--verbose`
254261
255262: Give verbose debugging output. Currently this only has an effect
data/bash_completion.tplnew file+62
@@ -0,0 +1,62 @@
1+#!/bin/bash
2+
3+# This script enables bash autocompletion for pandoc. To enable
4+# bash completion, add this to your .bashrc:
5+# eval "$(pandoc --bash-completion)"
6+
7+_pandoc()
8+{
9+ local cur prev opts lastc informats outformats datadir
10+ COMPREPLY=()
11+ cur="${COMP_WORDS[COMP_CWORD]}"
12+ prev="${COMP_WORDS[COMP_CWORD-1]}"
13+
14+ # These should be filled in by pandoc:
15+ opts="%s"
16+ informats="%s"
17+ outformats="%s"
18+ datadir="%s"
19+
20+ case "${prev}" in
21+ --from|-f|--read|-r)
22+ COMPREPLY=( $(compgen -W "${informats}" -- ${cur}) )
23+ return 0
24+ ;;
25+ --to|-t|--write|-w|-D|--print-default-template)
26+ COMPREPLY=( $(compgen -W "${outformats}" -- ${cur}) )
27+ return 0
28+ ;;
29+ --email-obfuscation)
30+ COMPREPLY=( $(compgen -W "references javascript none" -- ${cur}) )
31+ return 0
32+ ;;
33+ --latex-engine)
34+ COMPREPLY=( $(compgen -W "pdflatex lualatex xelatex" -- ${cur}) )
35+ return 0
36+ ;;
37+ --print-default-data-file)
38+ COMPREPLY=( $(compgen -W "reference.odt reference.docx $(find ${datadir} | sed -e 's/.*\/data\///')" -- ${cur}) )
39+ return 0
40+ ;;
41+ --highlight-style)
42+ COMPREPLY=( $(compgen -W "pygments tango espresso zenburn kate monochrome haddock" -- ${cur}) )
43+ return 0
44+ ;;
45+ *)
46+ ;;
47+ esac
48+
49+ case "${cur}" in
50+ -*)
51+ COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
52+ return 0
53+ ;;
54+ *)
55+ COMPREPLY=( $(compgen -f ${cur}) )
56+ return 0
57+ ;;
58+ esac
59+
60+}
61+
62+complete -F _pandoc pandoc
pandoc.cabal+2
@@ -105,6 +105,8 @@ Data-Files:
105105 data/dzslides/template.html
106106 -- sample lua custom writer
107107 data/sample.lua
108+ -- bash completion template
109+ data/bash_completion.tpl
108110 -- documentation
109111 README, COPYRIGHT
110112Extra-Source-Files:
pandoc.hs+18−1
@@ -71,7 +71,8 @@ import qualified Data.Text as T
7171import Control.Applicative ((<$>), (<|>))
7272import Text.Pandoc.Readers.Txt2Tags (getT2TMeta)
7373import Data.Monoid
74−
74+import Paths_pandoc (getDataDir)
75+import Text.Printf (printf)
7576import Text.Pandoc.Error
7677
7778type Transform = Pandoc -> Pandoc
@@ -880,6 +881,22 @@ options =
880881 (\opt -> return opt { optVerbose = True }))
881882 "" -- "Verbose diagnostic output."
882883
884+ , Option "" ["bash-completion"]
885+ (NoArg
886+ (\_ -> do
887+ ddir <- getDataDir
888+ tpl <- readDataFileUTF8 Nothing "bash_completion.tpl"
889+ let optnames (Option shorts longs _ _) =
890+ map (\c -> ['-',c]) shorts ++
891+ map ("--" ++) longs
892+ let allopts = unwords (concatMap optnames options)
893+ UTF8.hPutStrLn stdout $ printf tpl allopts
894+ (unwords (map fst readers))
895+ (unwords ("pdf": map fst writers))
896+ ddir
897+ exitWith ExitSuccess ))
898+ "" -- "Print bash completion script"
899+
883900 , Option "v" ["version"]
884901 (NoArg
885902 (\_ -> do