# calibre Bash Shell Completion
_calibre()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="--version -h --help --with-library --start-in-tray -v --verbose --no-update-check --ignore-plugins -s --shutdown-running-calibre --detach"
    pics="@(gif|bmp|png|jpeg|jpg|GIF|BMP|PNG|JPEG|JPG)"

    case "${prev}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
    esac

    case "${cur}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      -* )
         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
         return 0
         ;;
      *  )
        _filedir '@(['1', '1', '2', '2', '3', '3', '4', '4', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'E', 'E', 'E', 'E', 'E', 'E', 'F', 'F', 'F', 'F', 'F', 'F', 'H', 'H', 'H', 'H', 'H', 'H', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'J', 'J', 'K', 'K', 'K', 'K', 'K', 'K', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'N', 'N', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'S', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'U', 'U', 'U', 'U', 'V', 'V', 'W', 'W', 'W', 'W', 'W', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'e', 'e', 'e', 'e', 'e', 'e', 'f', 'f', 'f', 'f', 'f', 'f', 'h', 'h', 'h', 'h', 'h', 'h', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'j', 'j', 'k', 'k', 'k', 'k', 'k', 'k', 'l', 'l', 'l', 'l', 'l', 'l', 'l', 'l', 'l', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'n', 'n', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 's', 's', 's', 's', 's', 't', 't', 't', 't', 't', 't', 't', 't', 't', 't', 't', 't', 't', 't', 't', 't', 't', 't', 'u', 'u', 'u', 'u', 'v', 'v', 'w', 'w', 'w', 'w', 'w', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'])'
        return 0
        ;;
    esac

}
complete -o filenames -F _calibre calibre

_lrf2lrs()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="--version -h --help -o --output --dont-output-resources --verbose"
    pics="@(gif|bmp|png|jpeg|jpg|GIF|BMP|PNG|JPEG|JPG)"

    case "${prev}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
    esac

    case "${cur}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      -* )
         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
         return 0
         ;;
      *  )
        _filedir '@(['F', 'L', 'R', 'f', 'l', 'r', '|'])'
        return 0
        ;;
    esac

}
complete -o filenames -F _lrf2lrs lrf2lrs

_ebook_meta()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="--version -h --help -t --title -a --authors --title-sort --author-sort --cover -c --comments -p --publisher --category -s --series -i --index -r --rating --isbn --identifier --tags -k --book-producer -l --language -d --date --get-cover --to-opf --from-opf --lrf-bookid"
    pics="@(gif|bmp|png|jpeg|jpg|GIF|BMP|PNG|JPEG|JPG)"

    case "${prev}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      -c )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      --to-opf )
           _filedir ["'", "'", '(', ')', '@', 'f', 'o', 'p']
           return 0
         ;;
    
      --from-opf )
           _filedir ["'", "'", '(', ')', '@', 'f', 'o', 'p']
           return 0
         ;;
    
    esac

    case "${cur}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      -c )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      --to-opf )
           _filedir ["'", "'", '(', ')', '@', 'f', 'o', 'p']
           return 0
         ;;
    
      --from-opf )
           _filedir ["'", "'", '(', ')', '@', 'f', 'o', 'p']
           return 0
         ;;
    
      -* )
         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
         return 0
         ;;
      *  )
        _filedir '@(['1', '1', '2', '2', '3', '3', '4', '4', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C', 'D', 'D', 'D', 'D', 'D', 'E', 'E', 'F', 'F', 'F', 'F', 'F', 'H', 'H', 'H', 'I', 'I', 'I', 'I', 'I', 'I', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'M', 'M', 'M', 'M', 'M', 'M', 'M', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'S', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'U', 'U', 'W', 'W', 'W', 'W', 'X', 'X', 'X', 'X', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'a', 'a', 'a', 'a', 'a', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'c', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'd', 'd', 'e', 'e', 'f', 'f', 'f', 'f', 'f', 'h', 'h', 'h', 'i', 'i', 'i', 'i', 'i', 'i', 'l', 'l', 'l', 'l', 'l', 'l', 'l', 'm', 'm', 'm', 'm', 'm', 'm', 'm', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', 's', 't', 't', 't', 't', 't', 't', 't', 't', 't', 't', 'u', 'u', 'w', 'w', 'w', 'w', 'x', 'x', 'x', 'x', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', 'z', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'])'
        return 0
        ;;
    esac

}
complete -o filenames -F _ebook_meta ebook-meta

_ebook_polish()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="--version -h --help -e --embed-fonts -f --subset-fonts -c --cover -o --opf -j --jacket --remove-jacket -p --smarten-punctuation -u --remove-unused-css -i --compress-images --verbose"
    pics="@(gif|bmp|png|jpeg|jpg|GIF|BMP|PNG|JPEG|JPG)"

    case "${prev}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      -c )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      --opf )
           _filedir ["'", "'", '(', ')', '@', 'f', 'o', 'p']
           return 0
         ;;
    
      -o )
           _filedir ["'", "'", '(', ')', '@', 'f', 'o', 'p']
           return 0
         ;;
    
    esac

    case "${cur}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      -c )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      --opf )
           _filedir ["'", "'", '(', ')', '@', 'f', 'o', 'p']
           return 0
         ;;
    
      -o )
           _filedir ["'", "'", '(', ')', '@', 'f', 'o', 'p']
           return 0
         ;;
    
      -* )
         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
         return 0
         ;;
      *  )
        _filedir '@([u'3', u'3', u'A', u'B', u'E', u'P', u'U', u'W', u'Z', u'a', u'b', u'e', u'p', u'u', u'w', u'z', u'|', u'|', u'|'])'
        return 0
        ;;
    esac

}
complete -o filenames -F _ebook_polish ebook-polish

_lrfviewer()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="--version -h --help --verbose --visual-debug --disable-hyphenation --white-background --profile"
    pics="@(gif|bmp|png|jpeg|jpg|GIF|BMP|PNG|JPEG|JPG)"

    case "${prev}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
    esac

    case "${cur}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      -* )
         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
         return 0
         ;;
      *  )
        _filedir '@(['F', 'L', 'R', 'f', 'l', 'r', '|'])'
        return 0
        ;;
    esac

}
complete -o filenames -F _lrfviewer lrfviewer

_ebook_viewer()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="--version -h --help --raise-window -f --full-screen --fullscreen --debug-javascript --open-at --continue --detach"
    pics="@(gif|bmp|png|jpeg|jpg|GIF|BMP|PNG|JPEG|JPG)"

    case "${prev}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
    esac

    case "${cur}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      -* )
         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
         return 0
         ;;
      *  )
        _filedir '@([u'2', u'2', u'3', u'3', u'4', u'4', u'A', u'A', u'A', u'A', u'A', u'B', u'B', u'B', u'B', u'B', u'B', u'B', u'B', u'B', u'B', u'B', u'C', u'C', u'C', u'C', u'C', u'C', u'C', u'C', u'C', u'C', u'C', u'D', u'D', u'D', u'D', u'D', u'D', u'D', u'D', u'D', u'D', u'D', u'D', u'D', u'E', u'E', u'E', u'E', u'E', u'E', u'E', u'E', u'E', u'F', u'F', u'F', u'F', u'F', u'H', u'H', u'H', u'H', u'H', u'H', u'H', u'H', u'I', u'I', u'I', u'I', u'I', u'I', u'J', u'J', u'K', u'L', u'L', u'L', u'L', u'L', u'L', u'L', u'L', u'L', u'L', u'M', u'M', u'M', u'M', u'M', u'M', u'M', u'M', u'M', u'M', u'M', u'M', u'M', u'M', u'N', u'N', u'N', u'O', u'O', u'O', u'O', u'O', u'O', u'O', u'O', u'O', u'P', u'P', u'P', u'P', u'P', u'P', u'P', u'P', u'P', u'P', u'P', u'R', u'R', u'R', u'R', u'R', u'R', u'R', u'R', u'R', u'S', u'S', u'S', u'T', u'T', u'T', u'T', u'T', u'T', u'T', u'T', u'T', u'T', u'T', u'T', u'T', u'T', u'T', u'T', u'T', u'T', u'T', u'U', u'U', u'U', u'V', u'V', u'W', u'W', u'W', u'W', u'W', u'X', u'X', u'X', u'X', u'X', u'X', u'X', u'Z', u'Z', u'Z', u'Z', u'Z', u'Z', u'Z', u'_', u'_', u'a', u'a', u'a', u'a', u'a', u'b', u'b', u'b', u'b', u'b', u'b', u'b', u'b', u'b', u'b', u'b', u'c', u'c', u'c', u'c', u'c', u'c', u'c', u'c', u'c', u'c', u'c', u'd', u'd', u'd', u'd', u'd', u'd', u'd', u'd', u'd', u'd', u'd', u'd', u'd', u'e', u'e', u'e', u'e', u'e', u'e', u'e', u'e', u'e', u'f', u'f', u'f', u'f', u'f', u'h', u'h', u'h', u'h', u'h', u'h', u'h', u'h', u'i', u'i', u'i', u'i', u'i', u'i', u'j', u'j', u'k', u'l', u'l', u'l', u'l', u'l', u'l', u'l', u'l', u'l', u'l', u'm', u'm', u'm', u'm', u'm', u'm', u'm', u'm', u'm', u'm', u'm', u'm', u'm', u'm', u'n', u'n', u'n', u'o', u'o', u'o', u'o', u'o', u'o', u'o', u'o', u'o', u'p', u'p', u'p', u'p', u'p', u'p', u'p', u'p', u'p', u'p', u'p', u'r', u'r', u'r', u'r', u'r', u'r', u'r', u'r', u'r', u's', u's', u's', u't', u't', u't', u't', u't', u't', u't', u't', u't', u't', u't', u't', u't', u't', u't', u't', u't', u't', u't', u'u', u'u', u'u', u'v', u'v', u'w', u'w', u'w', u'w', u'w', u'x', u'x', u'x', u'x', u'x', u'x', u'x', u'z', u'z', u'z', u'z', u'z', u'z', u'z', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|'])'
        return 0
        ;;
    esac

}
complete -o filenames -F _ebook_viewer ebook-viewer

_ebook_edit()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="--version -h --help --detach"
    pics="@(gif|bmp|png|jpeg|jpg|GIF|BMP|PNG|JPEG|JPG)"

    case "${prev}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
    esac

    case "${cur}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      -* )
         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
         return 0
         ;;
      *  )
        _filedir '@([u'3', u'3', u'A', u'B', u'C', u'D', u'E', u'H', u'H', u'H', u'H', u'L', u'L', u'M', u'M', u'M', u'M', u'O', u'P', u'T', u'T', u'T', u'T', u'U', u'W', u'X', u'X', u'X', u'Z', u'a', u'b', u'c', u'd', u'e', u'h', u'h', u'h', u'h', u'l', u'l', u'm', u'm', u'm', u'm', u'o', u'p', u't', u't', u't', u't', u'u', u'w', u'x', u'x', u'x', u'z', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|', u'|'])'
        return 0
        ;;
    esac

}
complete -o filenames -F _ebook_edit ebook-edit

_fetch_ebook_metadata()
{
    local cur opts
    local IFS=$'|\t'
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    opts="--version|-h|--help|-t|--title|-a|--authors|-i|--isbn|-v|--verbose|-o|--opf|-c|--cover|-d|--timeout|-p|--allowed-plugin"
    words=""

    case "${cur}" in
      -* )
         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
         COMPREPLY=( $( echo ${COMPREPLY[@]} | sed 's/ /\\ /g' | tr '\n' '\t' ) )
         return 0
         ;;
      *  )
         COMPREPLY=( $(compgen -W "${words}" -- ${cur}) )
         COMPREPLY=( $( echo ${COMPREPLY[@]} | sed 's/ /\\ /g' | tr '\n' '\t' ) )
         return 0
         ;;
    esac

}
complete -F _fetch_ebook_metadata fetch-ebook-metadata

_calibre_smtp()
{
    local cur opts
    local IFS=$'|\t'
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    opts="--version|-h|--help|-l|--localhost|-o|--outbox|-f|--fork|-t|--timeout|-v|--verbose|-a|--attachment|-s|--subject|-r|--relay|--port|-u|--username|-p|--password|-e|--encryption-method"
    words=""

    case "${cur}" in
      -* )
         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
         COMPREPLY=( $( echo ${COMPREPLY[@]} | sed 's/ /\\ /g' | tr '\n' '\t' ) )
         return 0
         ;;
      *  )
         COMPREPLY=( $(compgen -W "${words}" -- ${cur}) )
         COMPREPLY=( $( echo ${COMPREPLY[@]} | sed 's/ /\\ /g' | tr '\n' '\t' ) )
         return 0
         ;;
    esac

}
complete -F _calibre_smtp calibre-smtp

_calibre_server()
{
    local cur opts
    local IFS=$'|\t'
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    opts="--version|-h|--help|-p|--port|-t|--timeout|--thread-pool|--password|--username|--develop|--max-cover|--max-opds-items|--max-opds-ungrouped-items|--url-prefix|--with-library|--pidfile|--daemonize|--restriction|--virtual-library|--auto-reload"
    words=""

    case "${cur}" in
      -* )
         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
         COMPREPLY=( $( echo ${COMPREPLY[@]} | sed 's/ /\\ /g' | tr '\n' '\t' ) )
         return 0
         ;;
      *  )
         COMPREPLY=( $(compgen -W "${words}" -- ${cur}) )
         COMPREPLY=( $( echo ${COMPREPLY[@]} | sed 's/ /\\ /g' | tr '\n' '\t' ) )
         return 0
         ;;
    esac

}
complete -F _calibre_server calibre-server

_calibre_debug()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="--version -h --help -c --command -e --exec-file -f --subset-font -d --debug-device-driver -g --gui --gui-debug -w --viewer --paths --add-simple-plugin --reinitialize-db -m --inspect-mobi -t --edit-book -x --explode-book --export-all-calibre-data --import-calibre-data -s --shutdown-running-calibre --test-build -r --run-plugin --diff --default-programs --new-server"
    pics="@(gif|bmp|png|jpeg|jpg|GIF|BMP|PNG|JPEG|JPG)"

    case "${prev}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
    esac

    case "${cur}" in
      --cover )
           _filedir ['$', 'c', 'i', 'p', 's', '{', '}']
           return 0
         ;;
    
      -* )
         COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
         return 0
         ;;
      *  )
        _filedir '@(['3', '3', 'A', 'A', 'B', 'C', 'C', 'D', 'E', 'E', 'I', 'I', 'M', 'O', 'O', 'P', 'P', 'R', 'W', 'W', 'X', 'Y', 'Z', 'Z', 'a', 'a', 'b', 'c', 'c', 'd', 'e', 'e', 'i', 'i', 'm', 'o', 'o', 'p', 'p', 'r', 'w', 'w', 'x', 'y', 'z', 'z', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|', '|'])'
        return 0
        ;;
    esac

}
complete -o filenames -F _calibre_debug calibre-debug


_ebook_device_ls()
{
local pattern search listing prefix
pattern="$1"
search="$1"
if [[ -n "{$pattern}" ]]; then
    if [[ "${pattern:(-1)}" == "/" ]]; then
    pattern=""
    else
    pattern="$(basename ${pattern} 2> /dev/null)"
    search="$(dirname ${search} 2> /dev/null)"
    fi
fi

if [[  "x${search}" == "x" || "x${search}" == "x." ]]; then
    search="/"
fi

listing="$(ebook-device ls ${search} 2>/dev/null)"

prefix="${search}"
if [[ "x${prefix:(-1)}" != "x/" ]]; then
    prefix="${prefix}/"
fi

echo $(compgen -P "${prefix}" -W "${listing}" "${pattern}")
}

_ebook_device()
{
local cur prev
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=()
case "${prev}" in
    ls|rm|mkdir|touch|cat )
        COMPREPLY=( $(_ebook_device_ls "${cur}") )
        return 0
        ;;
    cp )
        if [[ ${cur} == dev:* ]]; then
        COMPREPLY=( $(_ebook_device_ls "${cur:7}") )
        return 0
        else
        _filedir
        return 0
        fi
        ;;
    dev )
        COMPREPLY=( $(compgen -W "cp ls rm mkdir touch cat info books df" "${cur}") )
        return 0
        ;;
    * )
        if [[ ${cur} == dev:* ]]; then
        COMPREPLY=( $(_ebook_device_ls "${cur:7}") )
        return 0
        else
        if [[ ${prev} == dev:* ]]; then
            _filedir
            return 0
        else
            COMPREPLY=( $(compgen -W "dev:" "${cur}") )
            return 0
        fi
        return 0
        fi
    ;;
esac
}
complete -o nospace  -F _ebook_device ebook-device

complete -o nospace -C calibre-complete ebook-convert
