Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions lua/notmuch/handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ H.default_view_handler = function(attachment)
-- Check if the tool exists
if vim.fn.executable(cmd.tool) == 1 then
local output
if type(cmd.command(path)) == 'table' then
output = vim.fn.system(cmd.command(path))
local success
local command = cmd.command(path)
if type(command) == 'table' then
local obj = vim.system(command):wait()
output = obj.stdout
success = (obj.code == 0)
else
output = vim.fn.system(cmd.command(path))
output = vim.fn.system(command)
success = (vim.v.shell_error == 0)
end

if vim.v.shell_error == 0 then
if success then
return output
end
end
Expand All @@ -54,7 +59,7 @@ H.default_view_handler = function(attachment)
local ext = path:match('%.([^%.]+)$') or ''

-- HTML files (most common)
if filetype:match('text/html') or ext:match('^html?$') then
if filetype:match('^text/html$') or ext:match('^html?$') then
return try_commands({
{ tool = 'w3m', command = function(p) return { 'w3m', '-T', 'text/html', '-dump', p } end },
{ tool = 'lynx', command = function(p) return { 'lynx', '-dump', '-nolist', p } end },
Expand All @@ -63,7 +68,7 @@ H.default_view_handler = function(attachment)
end

-- PDF files
if filetype:match('application/pdf') or ext == 'pdf' then
if filetype:match('^application/pdf$') or ext == 'pdf' then
return try_commands({
{ tool = 'pdftotext', command = function(p) return { 'pdftotext', '-layout', p, '-' } end },
{ tool = 'mutool', command = function(p) return { 'mutool', 'draw', '-F', 'txt', p } end },
Expand All @@ -90,7 +95,7 @@ H.default_view_handler = function(attachment)
end

-- Markdown
if filetype:match('text/markdown') or ext:match('^md$') then
if filetype:match('^text/markdown$') or ext:match('^md$') then
return try_commands({
{ tool = 'pandoc', command = function(p) return { 'pandoc', '-t', 'plain', p } end },
{ tool = 'mdcat', command = function(p) return { 'mdcat', p } end },
Expand Down