├── README.markdown └── pandoc-completion.bash /README.markdown: -------------------------------------------------------------------------------- 1 | **No Longer In Development** 2 | 3 | As of 1.15.1.1, pandoc has [built-in support for bash completion](https://github.com/jgm/pandoc/commit/73824908aab1d910996cf4db7baf722aecc32d31), so you should use that instead. 4 | 5 | 6 | pandoc-completion.bash 7 | ---------------------- 8 | 9 | `pandoc-completion.bash` is a [bash completion script][] for [pandoc][]. 10 | It supports completion of `pandoc`'s command-line options, as well as 11 | completion of filenames in the pandoc data directory, `~/.pandoc`, and 12 | the csl styles directory, `~/.csl`, where appropriate. 13 | 14 | installation 15 | ------------ 16 | 17 | First get `pandoc-completion.bash`, 18 | 19 | git clone git@github.com:dsanson/pandoc-completion.git 20 | 21 | or (if you don't want to be bothered with git) 22 | 23 | curl -O https://raw.github.com/dsanson/pandoc-completion/master/pandoc-completion.bash 24 | 25 | Then put something like 26 | 27 | [[ -s "/path/to/pandoc-completion.bash" ]] && source "/path/to/pandoc-completion.bash" 28 | 29 | in your `.bashrc`. 30 | 31 | To use bash completion scripts with [zsh][], you need to load `bashcompinit` first, so put something like 32 | 33 | ```bash 34 | 35 | autoload bashcompinit 36 | bashcompinit 37 | source "/path/to/pandoc-completion.bash" 38 | 39 | ``` 40 | 41 | in your `.zshrc`. 42 | 43 | which version of pandoc? 44 | ------------------------ 45 | 46 | New versions of pandoc sometimes bring new command-line options and sometimes remove old command-line options. I have not been as careful about keeping track of this as I might have been: I usually use the development version of pandoc, updating every couple of weeks. And I try to keep this script in sync with what I am using. 47 | 48 | In recent commits, you will find a line like this 49 | 50 | ```bash 51 | # Pandoc Version: 1.10.0.3 52 | ``` 53 | 54 | at the beginning of the script. The script should exactly match the options available in that version of pandoc. Since the command-line options are fairly stable, you probably don't need to worry about this too much. 55 | 56 | A good quick way to check your version of pandoc against your version of pandoc-completion.bash is to run `pandoc --help`, and compare the output against the completion script, looking to see if the input and output formats match and if the options match. 57 | 58 | some further details about the implementation 59 | --------------------------------------------- 60 | 61 | The script completes long options that take arguments as 62 | 63 | --opt arg 64 | 65 | rather than 66 | 67 | --opt=arg 68 | 69 | (although the documentation doesn't don't make this clear, `pandoc` 70 | supports both styles). But if you type something like 71 | 72 | pandoc --opt= 73 | 74 | it should still work as expected. 75 | 76 | Some options take filenames as arguments, and the script tries to be 77 | smart about where it looks for possible filename completions: 78 | 79 | - `--template`: the current directory or `~/.pandoc/templates`; 80 | - `--csl`: filenames ending in `.csl`, in the current directory or 81 | `~/.csl`; 82 | - `--citation-abbreviations`: filenames ending in `.json`, in the 83 | current directory or `~/.csl`; 84 | - `--biliography`: filenames ending in supported bibliography 85 | extensions (`.bib`, `.mods`, etc.), in the current directory or in 86 | `~/.pandoc`; 87 | - `--reference-odt` and `--reference-docx`: filenames ending in `.odt` 88 | or `.docx` in the current directory or `~/.pandoc`. 89 | 90 | adding your own completion shortcuts 91 | ------------------------------------ 92 | 93 | If there is an option that you use regularly, you might want to create a completion shortcut for it. For example, in my personal copy of `pandoc-completions.bash`, I have added two instances to the case-loop that occurs near the end of the script, so that `-x` expands to `--latex-engine xelatex` and `-b` expands to `--bibliography $HOME/.pandoc/default.bib`: 94 | 95 | ```bash 96 | case "$cur" in 97 | -x) 98 | COMPREPLY=( "--latex-engine xelatex" ) 99 | return 0 100 | ;; 101 | -b) 102 | COMPREPLY=( "--bibliography $HOME/.pandoc/default.bib") 103 | return 0 104 | ;; 105 | -*) 106 | COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) 107 | return 0 108 | ;; 109 | *) 110 | COMPREPLY=( $(compgen -f -- ${cur}) ) 111 | ;; 112 | esac 113 | ``` 114 | 115 | pandoc.usage 116 | ------------ 117 | 118 | This repository used to include both `pandoc-completion.bash` and 119 | `pandoc.usage`. The latter was a usage file for use with 120 | [Compleat][], a haskell program that generates bash and zsh completions 121 | based upon an abstract specification of a command's command line options. 122 | I hoped it would ultimately provide a more elegant solution and be 123 | easier to maintain, but 124 | 125 | 1. I couldn't get it to provide completions for full paths to files not 126 | in the current directory; 127 | 2. I couldn't get it to respect appropriate restrictions on 128 | completions. 129 | 130 | So I removed `pandoc.usage` from the repo. If you are looking for it, 131 | the most recent version can be found [here][]. If you can get it to work, let me know! 132 | 133 | [bash completion script]: http://www.hypexr.org/bash_tutorial.php#completion 134 | [pandoc]: http://johnmacfarlane.net/pandoc/ 135 | [zsh]: http://zsh.sourceforge.net/ 136 | [Compleat]: https://github.com/mbrubeck/compleat 137 | [here]: https://github.com/dsanson/pandoc-completion/commit/72eab2016eafa4957b1cfac07989d4f8ab208e4e 138 | -------------------------------------------------------------------------------- /pandoc-completion.bash: -------------------------------------------------------------------------------- 1 | # pandoc completion 2 | # 3 | # (c) 2012, 2013 David Sanson 4 | # 5 | # Copying and distribution of this file, with or without modification, 6 | # are permitted in any medium without royalty provided the copyright 7 | # notice and this notice are preserved. This file is offered as-is, 8 | # without any warranty. 9 | # 10 | # Pandoc Version: 1.11 11 | # 12 | 13 | function _completer() 14 | { 15 | local command cur prev opts 16 | command="$1" 17 | COMPREPLY=() 18 | cur="${COMP_WORDS[COMP_CWORD]}" 19 | prev="${COMP_WORDS[COMP_CWORD-1]}" 20 | if [ ${prev} == '=' ] 21 | then 22 | prev="${COMP_WORDS[COMP_CWORD-2]}" 23 | fi 24 | 25 | extensible="markdown markdown_github markdown_mmd \ 26 | markdown_phpextra markdown_strict" 27 | 28 | input="docbook haddock html json latex mediawiki \ 29 | native opml rst textile" 30 | 31 | input="$input $extensible" 32 | 33 | output="asciidoc beamer context docbook docx dzslides \ 34 | epub epub3 fb2 html html5 json latex man mediawiki \ 35 | native odt opendocument opml org plain revealjs \ 36 | rst rtf s5 slideous slidy texinfo textile" 37 | 38 | output="$output $extensible" 39 | 40 | extensions="escaped_line_breaks blank_before_header header_attributes \ 41 | auto_identifiers implicit_header_references \ 42 | blank_before_blockquote fenced_code_blocks line_blocks \ 43 | fancy_lists startnum definition_lists example_lists \ 44 | simple_tables table_captions multiline_tables \ 45 | table_captions grid_tables table_captions pipe_tables \ 46 | table_captions pandoc_title_block all_symbols_escapable \ 47 | intraword_underscores strikeout superscript subscript \ 48 | inline_code_attributes tex_math_dollars raw_html \ 49 | markdown_in_html_blocks raw_tex latex_macros \ 50 | implicit_figures footnotes inline_notes citations \ 51 | hard_line_breaks tex_math_single_backslash \ 52 | tex_math_double_backslash markdown_attribute \ 53 | mmd_title_block abbreviations autolink_bare_uris \ 54 | link_attributes mmd_header_identifiers" 55 | 56 | 57 | bibs="(bib)|(mods)|(ris)|(bbx)|(enl)|(xml)|(wos)|(copac)|(json)|(medline)" 58 | 59 | highlight_styles="pygments kate monochrome espresso zenburn haddock tango" 60 | 61 | latex_engines="pdflatex lualatex xelatex" 62 | 63 | pandoc_opts=" \ 64 | -f -r --from --read \ 65 | -t -w --to --write \ 66 | -o --output \ 67 | --data-dir \ 68 | --strict \ 69 | -R --parse-raw \ 70 | -S --smart \ 71 | --old-dashes \ 72 | --base-header-level \ 73 | --indented-code-classes \ 74 | --normalize \ 75 | -p --preserve-tabs \ 76 | --tab-stop \ 77 | -s --standalone \ 78 | --template \ 79 | -V --variable \ 80 | -D --print-default-template \ 81 | --print-sample-lua-writer \ 82 | --no-wrap \ 83 | --columns \ 84 | --toc --table-of-contents \ 85 | --toc-depth \ 86 | --no-highlight \ 87 | --highlight-style \ 88 | -H --include-in-header \ 89 | -B --include-before-body \ 90 | -A --include-after-body \ 91 | --self-contained \ 92 | --offline \ 93 | -5 --html5 \ 94 | --html-q-tags \ 95 | --ascii \ 96 | --reference-links \ 97 | --atx-headers \ 98 | --chapters \ 99 | -N --number-sections \ 100 | --number-offsetS \ 101 | --no-tex-ligatures \ 102 | --listings \ 103 | -i --incremental \ 104 | --slide-level \ 105 | --section-divs \ 106 | --default-image-extension \ 107 | --email-obfuscation \ 108 | --id-prefix \ 109 | -T --title-prefix \ 110 | -c --css \ 111 | --reference-odt \ 112 | --reference-docx \ 113 | --epub-stylesheet \ 114 | --epub-cover-image \ 115 | --epub-metadata \ 116 | --epub-embed-font \ 117 | --epub-chapter-level \ 118 | --latex-engine \ 119 | --bibliography \ 120 | --csl \ 121 | --citation-abbreviations \ 122 | --natbib \ 123 | --biblatex \ 124 | -m --latexmathml --asciimathml \ 125 | --mathml \ 126 | --mimetex \ 127 | --webtex \ 128 | --jsmath \ 129 | --mathjax \ 130 | --gladtex \ 131 | --dump-args \ 132 | --ignore-args \ 133 | -v --version \ 134 | -h --help" 135 | 136 | 137 | if [ "$command" == "pandoc" ] 138 | then 139 | opts="$pandoc_opts" 140 | else 141 | return 0 142 | fi 143 | 144 | case "$prev" in 145 | -f|-r|--from|--read) 146 | if [[ $cur == *[+-] ]] 147 | then 148 | suggestions="" 149 | for e in $extensions 150 | do 151 | suggestions="$cur$e $suggestions" 152 | done 153 | COMPREPLY=( $( compgen -W "$suggestions" -- ${cur} ) ) 154 | elif [[ $cur == *[+-]* ]] 155 | then 156 | suggestions="" 157 | root=${cur%[+-]*} 158 | suffix=${cur##*[+-]} 159 | connective=${cur#$root} 160 | connective=${connective:0:1} 161 | for e in $extensions 162 | do 163 | suggestions="$root$connective$e $suggestions" 164 | done 165 | COMPREPLY=( $( compgen -W "$suggestions" -- ${cur} ) ) 166 | else 167 | COMPREPLY=( $( compgen -W "$input" -- ${cur} ) ) 168 | fi 169 | return 0 170 | ;; 171 | -t|-w|-D|--to|--write|--print-default-template) 172 | if [[ $cur == *[+-] ]] 173 | then 174 | suggestions="" 175 | for e in $extensions 176 | do 177 | suggestions="$cur$e $suggestions" 178 | done 179 | COMPREPLY=( $( compgen -W "$suggestions" -- ${cur} ) ) 180 | elif [[ $cur == *[+-]* ]] 181 | then 182 | suggestions="" 183 | root=${cur%[+-]*} 184 | suffix=${cur##*[+-]} 185 | connective=${cur#$root} 186 | connective=${connective:0:1} 187 | for e in $extensions 188 | do 189 | suggestions="$root$connective$e $suggestions" 190 | done 191 | COMPREPLY=( $( compgen -W "$suggestions" -- ${cur} ) ) 192 | else 193 | COMPREPLY=( $( compgen -W "$output" -- ${cur} ) ) 194 | fi 195 | return 0 196 | ;; 197 | --highlight-style) 198 | COMPREPLY=( $( compgen -W "$highlight_styles" -- ${cur} ) ) 199 | return 0 200 | ;; 201 | --latex-engine) 202 | COMPREPLY=( $( compgen -W "$latex_engines" -- ${cur} )) 203 | return 0 204 | ;; 205 | --data-dir) 206 | COMPREPLY=( $( compgen -d -- ${cur} ) ) 207 | return 0 208 | ;; 209 | --email-obfuscation) 210 | COMPREPLY=( $( compgen -W "none javascript references" -- ${cur} ) ) 211 | return 0 212 | ;; 213 | --bibliography) 214 | COMPREPLY=( $( ls $HOME/.pandoc/ 2> /dev/null | egrep "^${cur}.*\.${bibs}$" | sed "s#^#$HOME/.pandoc/#" ) ) 215 | COMPREPLY=( ${COMPREPLY[@]} $(compgen -f -- ${cur} | egrep "\.${bibs}$" ) ) 216 | return 0 217 | ;; 218 | --template) 219 | COMPREPLY=( $( ls $HOME/.pandoc/templates/ 2> /dev/null | grep "^${cur}" ) ) 220 | COMPREPLY=( ${COMPREPLY[@]} $(compgen -f -- ${cur} ) ) 221 | return 0 222 | ;; 223 | --csl) 224 | COMPREPLY=( $( ls $HOME/.csl/ 2> /dev/null | egrep "^${cur}.*\.csl$" ) ) 225 | COMPREPLY=( ${COMPREPLY[@]} $(compgen -f -- ${cur} | grep ".csl$" ) ) 226 | return 0 227 | ;; 228 | --citation-abbreviations) 229 | COMPREPLY=( $( ls $HOME/.csl/ 2> /dev/null | egrep "^${cur}.*\.json$" | sed "s#^#$HOME/.csl/#" ) ) 230 | COMPREPLY=( ${COMPREPLY[@]} $(compgen -f -- ${cur} | grep ".json$" ) ) 231 | return 0 232 | ;; 233 | --reference-odt) 234 | COMPREPLY=( $( ls $HOME/.pandoc/ 2> /dev/null | egrep "^${cur}.*\.odt$" | sed s#^#$HOME/.pandoc/# ) ) 235 | COMPREPLY=( ${COMPREPLY[@]} $(compgen -f -- ${cur} | egrep "*.odt" ) ) 236 | return 0 237 | ;; 238 | --reference-docx) 239 | COMPREPLY=( $( ls $HOME/.pandoc/ 2> /dev/null | egrep "^${cur}.*\.docx$" | sed s#^#$HOME/.pandoc/# ) ) 240 | COMPREPLY=( ${COMPREPLY[@]} $(compgen -f -- ${cur} | egrep "*.docx" ) ) 241 | return 0 242 | ;; 243 | -o|--output) 244 | COMPREPLY=( $( compgen -f -- ${cur} | sed "s/\(.*\)\..*/\1/" | grep "${cur}"; compgen -f -- ${cur} ) ) 245 | return 0 246 | ;; 247 | esac 248 | 249 | case "$cur" in 250 | -*) 251 | COMPREPLY=( $(compgen -W "$opts" -- ${cur}) ) 252 | return 0 253 | ;; 254 | *) 255 | COMPREPLY=( $(compgen -f -- ${cur}) ) 256 | ;; 257 | esac 258 | } 259 | 260 | function _pandoc_completer() { 261 | _completer pandoc 262 | return 0 263 | } 264 | 265 | complete -F _pandoc_completer -o nospace pandoc 266 | 267 | --------------------------------------------------------------------------------