summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorSimon Hauser <Simon-Hauser@outlook.de>2021-02-01 14:50:01 +0100
committerGitHub <noreply@github.com>2021-02-01 14:50:01 +0100
commit9e76b1613a25cc6f63d17eb73432523924662619 (patch)
treeeed247a95abd53ea0f54e0eaafe0c8f0613d5440 /lua
parentfc54211868fcca8e53fec7071b3fab3591d250da (diff)
fix: remove env workaround for term_previewer (#482)
Also fixes #484
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/config.lua2
-rw-r--r--lua/telescope/previewers/term_previewer.lua59
2 files changed, 19 insertions, 42 deletions
diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua
index bfe8a6e..3a6f229 100644
--- a/lua/telescope/config.lua
+++ b/lua/telescope/config.lua
@@ -67,7 +67,7 @@ function config.set_defaults(defaults)
set("use_less", true)
set("color_devicons", true)
- set("set_env", {})
+ set("set_env", nil)
-- TODO: Add motions to keybindings
diff --git a/lua/telescope/previewers/term_previewer.lua b/lua/telescope/previewers/term_previewer.lua
index 31ca495..c402b4a 100644
--- a/lua/telescope/previewers/term_previewer.lua
+++ b/lua/telescope/previewers/term_previewer.lua
@@ -16,27 +16,21 @@ local previewers = {}
local bat_options = {"--style=plain", "--color=always", "--paging=always"}
local has_less = (vim.fn.executable('less') == 1) and conf.use_less
--- TODO(conni2461): Workaround for neovim/neovim#11751. Add only quotes when using else branch.
-local valuate_shell = function()
- local shell = vim.o.shell
- if string.find(shell, 'powershell.exe') or string.find(shell, 'cmd.exe') or
- string.find(shell, 'powershell') or string.find(shell, 'pwsh') then
- return ''
- else
- return "'"
- end
-end
-
-local add_quotes = valuate_shell()
-
local get_file_stat = function(filename)
return vim.loop.fs_stat(vim.fn.expand(filename)) or {}
end
-local function list_dir(dirname)
- local qdir = add_quotes .. vim.fn.expand(dirname) .. add_quotes
- return vim.fn.has('win32') == 1 and {'cmd.exe', '/c', 'dir', qdir} or { 'ls', '-la', qdir}
-end
+local list_dir = (function()
+ if vim.fn.has('win32') == 1 then
+ return function(dirname)
+ return { 'cmd.exe', '/c', 'dir', vim.fn.expand(dirname) }
+ end
+ else
+ return function(dirname)
+ return { 'ls', '-la', vim.fn.expand(dirname) }
+ end
+ end
+end)()
local bat_maker = function(filename, lnum, start, finish)
if get_file_stat(filename).type == 'directory' then
@@ -52,9 +46,9 @@ local bat_maker = function(filename, lnum, start, finish)
if has_less then
if start then
- table.insert(command, {"--pager", string.format("%sless -RS +%s%s", add_quotes, start, add_quotes)})
+ table.insert(command, {"--pager", string.format("less -RS +%s", start)})
else
- table.insert(command, {"--pager", string.format("%sless -RS%s", add_quotes, add_quotes)})
+ table.insert(command, {"--pager", "less -RS"})
end
else
if start and finish then
@@ -67,7 +61,7 @@ local bat_maker = function(filename, lnum, start, finish)
end
return flatten {
- command, bat_options, "--", add_quotes .. vim.fn.expand(filename) .. add_quotes
+ command, bat_options, "--", vim.fn.expand(filename)
}
end
@@ -86,13 +80,13 @@ local cat_maker = function(filename, _, start, _)
if has_less then
if start then
- return { 'less', '-RS', string.format('+%s', start), add_quotes .. vim.fn.expand(filename) .. add_quotes }
+ return { 'less', '-RS', string.format('+%s', start), vim.fn.expand(filename) }
else
- return { 'less', '-RS', add_quotes .. vim.fn.expand(filename) .. add_quotes }
+ return { 'less', '-RS', vim.fn.expand(filename) }
end
else
return {
- "cat", "--", add_quotes .. vim.fn.expand(filename) .. add_quotes
+ "cat", "--", vim.fn.expand(filename)
}
end
end
@@ -185,25 +179,8 @@ previewers.new_termopen_previewer = function(opts)
env = conf.set_env
}
- -- TODO(conni2461): Workaround for neovim/neovim#11751.
- local get_cmd = function(st)
- local shell = vim.o.shell
- if string.find(shell, 'powershell.exe') or string.find(shell, 'cmd.exe') or
- string.find(shell, 'powershell') or string.find(shell, 'pwsh') then
- return opts.get_command(entry, st)
- else
- local env = {}
- local cmd = opts.get_command(entry, st)
- if not cmd then return end
- for k, v in pairs(conf.set_env) do
- table.insert(env, k .. '=' .. v)
- end
- return table.concat(env, ' ') .. ' ' .. table.concat(cmd, ' ')
- end
- end
-
putils.with_preview_window(status, bufnr, function()
- local cmd = get_cmd(status)
+ local cmd = opts.get_command(entry, status)
if cmd then set_term_id(self, vim.fn.termopen(cmd, term_opts)) end
end)