Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bash completion: Weird behavior when spaces in filenames #2749

Closed
joallard opened this issue Mar 1, 2016 · 11 comments
Closed

Bash completion: Weird behavior when spaces in filenames #2749

joallard opened this issue Mar 1, 2016 · 11 comments

Comments

@joallard
Copy link

joallard commented Mar 1, 2016

I installed pandoc with brew on OS X (v1.16.0.2), and when I try to tab complete, I get not-very-useful behavior:

$ ll
total 0
-rw-r--r--  1 jon  staff  0  1 Mar 14:19 File 1 A B.txt
-rw-r--r--  1 jon  staff  0  1 Mar 14:19 File 1 C B.txt
-rw-r--r--  1 jon  staff  0  1 Mar 14:19 File 3 A B.txt
Jonathans-MacBook-Pro:foo jon$ pandoc F
1      3      A      B.txt  C      File
Jonathans-MacBook-Pro:foo jon$ pandoc File
1      3      A      B.txt  C      File
Jonathans-MacBook-Pro:foo jon$ pandoc File
1      3      A      B.txt  C      File
Jonathans-MacBook-Pro:foo jon$ pandoc File\ 1
1      3      A      B.txt  C      File
Jonathans-MacBook-Pro:foo jon$ pandoc File\ 3
1      3      A      B.txt  C      File
Jonathans-MacBook-Pro:foo jon$ pandoc File\ 3

Brew handles installing the bash completion, but just in case, I ran the eval line just to be sure.

Edit I'm noting this here for quick repro: $ mkdir pandoc-comp-test; cd pandoc-comp-test; touch File\ {1,3}\ {A,C}\ B.txt

@jgm
Copy link
Owner

jgm commented Mar 2, 2016

Hm, I'm not able to reproduce this (also on OSX). If I type
pandoc F and hit tab, it gets autocompleted to File,
and if I hit tab again, I get the three full filenames as
options.

+++ Jonathan Allard [Mar 01 16 11:21 ]:

I installed pandoc with brew on OS X (v1.16.0.2), and when I try to tab
complete, I get not-very-useful behavior:
$ ll
total 0
-rw-r--r-- 1 jon staff 0 1 Mar 14:19 File 1 A B.txt
-rw-r--r-- 1 jon staff 0 1 Mar 14:19 File 1 C B.txt
-rw-r--r-- 1 jon staff 0 1 Mar 14:19 File 3 A B.txt
Jonathans-MacBook-Pro:foo jon$ pandoc F
1 3 A B.txt C File
Jonathans-MacBook-Pro:foo jon$ pandoc File
1 3 A B.txt C File
Jonathans-MacBook-Pro:foo jon$ pandoc File
1 3 A B.txt C File
Jonathans-MacBook-Pro:foo jon$ pandoc File\ 1
1 3 A B.txt C File
Jonathans-MacBook-Pro:foo jon$ pandoc File\ 3
1 3 A B.txt C File
Jonathans-MacBook-Pro:foo jon$ pandoc File\ 3

Brew handles installing the bash completion, but just in case, I ran
the eval line just to be sure.


Reply to this email directly or [1]view it on GitHub.

References

  1. Bash completion: Weird behavior when spaces in filenames #2749

@joallard
Copy link
Author

joallard commented Mar 3, 2016

Shite. Something else must be up in my shell. Thanks for attempting to confirm so quickly John, you're doing great work on Pandoc. I'll close this and be in my bunk trying to figure it out, I'll update if I do.

@joallard joallard closed this as completed Mar 3, 2016
@joallard
Copy link
Author

joallard commented Dec 6, 2016

I'm really not finding it.

I can open a new shell, bash, and without the complete -F instruction, it's fine. As soon as I load the completion (and it's the only one in place), it bugs out.

I've tested that it was the same parameter fed to compgen -f, and the same output. Something seems to happen after that in my shell and I don't know what.

(Even tested with the latest Bash)

@joallard joallard reopened this Dec 6, 2016
@jgm
Copy link
Owner

jgm commented Dec 7, 2016

OK, yes, I can reproduce this. (I didn't reproduce your exact filenames before.)
Seems to have something to do with spaces in the filenames.

@jgm
Copy link
Owner

jgm commented Dec 7, 2016

Hm. See http://forums.fedoraforum.org/showthread.php?t=301974
which suggests there might be a bug.

Indeed, doing shopt -u progcomp in my shell fixed the problem
(but made pandoc completion of options stop working).

@jgm jgm closed this as completed in b073319 Dec 7, 2016
@jgm
Copy link
Owner

jgm commented Dec 7, 2016

Can you try the latest (commit b073319)?

It works better (and I added some missing options).

@jgm jgm reopened this Dec 7, 2016
@jgm
Copy link
Owner

jgm commented Dec 7, 2016

But still not quite right. If I type 'F', I no longer get the list of separate words. However, it should complete to File\ , and it doesn't.

@jgm
Copy link
Owner

jgm commented Dec 7, 2016

OK, I think I've got it this time.

@jgm jgm closed this as completed in afa675b Dec 7, 2016
@joallard
Copy link
Author

joallard commented Dec 8, 2016

Awesome. I'm not well equipped enough to compile, but if you were able to repro, that must be good. Thanks @jgm!

@jgm
Copy link
Owner

jgm commented Dec 8, 2016

Here's the output of pandoc --bash-completion (you'll need to change datadir of course):

# 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="-f -r --from --read -t -w --to --write -o --output --data-dir -R --parse-raw -S --smart --old-dashes --base-header-level --indented-code-classes -F --filter --normalize -p --preserve-tabs --tab-stop --track-changes --file-scope --extract-media -s --standalone --template -M --metadata -V --variable -D --print-default-template --print-default-data-file --dpi --no-wrap --wrap --columns --toc --table-of-contents --toc-depth --no-highlight --highlight-style -H --include-in-header -B --include-before-body -A --include-after-body --self-contained --html-q-tags --ascii --reference-links --reference-location --atx-headers --chapters --top-level-division -N --number-sections --number-offset --no-tex-ligatures --listings -i --incremental --slide-level --section-divs --default-image-extension --email-obfuscation --id-prefix -T --title-prefix -c --css --reference-odt --reference-docx --epub-stylesheet --epub-cover-image --epub-metadata --epub-embed-font --epub-chapter-level --latex-engine --latex-engine-opt --bibliography --csl --citation-abbreviations --natbib --biblatex -m --latexmathml --asciimathml --mathml --mimetex --webtex --jsmath --mathjax --katex --katex-stylesheet --gladtex --trace --dump-args --ignore-args --verbose --bash-completion --list-input-formats --list-output-formats --list-extensions --list-highlight-languages --list-highlight-styles -v --version -h --help"
    informats="native json markdown markdown_strict markdown_phpextra markdown_github markdown_mmd commonmark rst mediawiki docbook opml org textile html latex haddock twiki docx odt t2t epub"
    outformats="native json docx odt epub epub3 fb2 html html5 icml s5 slidy slideous dzslides revealjs docbook docbook5 opml opendocument latex beamer context texinfo man markdown markdown_strict markdown_phpextra markdown_github markdown_mmd plain rst mediawiki dokuwiki zimwiki textile rtf org asciidoc haddock commonmark tei"
    highlight_styles="pygments tango espresso zenburn kate monochrome haddock"
    datadir="/Users/jgm/src/pandoc/.stack-work/install/x86_64-osx/lts-7.9/8.0.1/share/x86_64-osx-ghc-8.0.1/pandoc-1.19"

    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
             ;;
         --wrap)
             COMPREPLY=( $(compgen -W "auto none preserve" -- ${cur}) )
             return 0
             ;;
         --track-changes)
             COMPREPLY=( $(compgen -W "accept reject all" -- ${cur}) )
             return 0
             ;;
         --reference-location)
             COMPREPLY=( $(compgen -W "block section document" -- ${cur}) )
             return 0
             ;;
         --top-level-division)
             COMPREPLY=( $(compgen -W "section chapter part" -- ${cur}) )
             return 0
             ;;
         --highlight-style)
             COMPREPLY=( $(compgen -W "${highlight_styles}" -- ${cur}) )
             return 0
             ;;
         *)
             ;;
    esac

    case "${cur}" in
         -*)
             COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
             return 0
             ;;
         *)
             local IFS=$'\n'
             COMPREPLY=( $(compgen -X '' -f "${cur}") )
             return 0
             ;;
    esac

}

complete -o filenames -o bashdefault -F _pandoc pandoc

@joallard
Copy link
Author

joallard commented Dec 8, 2016

Confirming fix. Thanks a bunch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants