Skip to content
Discussion options

You must be logged in to vote

I wrote a custom previewer to do this (using python). Here is the code in case anybody else wants it:

import sys
import mimetypes
import pathlib
import os

def get_mimetype(path):
    return mimetypes.guess_type(path)[0]

def handle_text(path):
    with open(path, 'r') as f:
        print(f.read())

def print_divider():
    print('-' * 80)

def handle_pdf(path):
    try:
        import fitz
        doc = fitz.open(path)
        num_pages = doc.pageCount
        text = clean_text(doc.getPageText(0))
        doc.close()
        print(f'Pages: {num_pages}')
        print(text)
    except ImportError:
        print('Install mupdf for PDF previews')

def clean_text(text):
    # remove all non-…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@gokcehan
Comment options

@ahrm
Comment options

Answer selected by CatsDeservePets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants