diff options
Diffstat (limited to 'lua/nvim-lsp-installer/installers/shell.lua')
| -rw-r--r-- | lua/nvim-lsp-installer/installers/shell.lua | 62 |
1 files changed, 49 insertions, 13 deletions
diff --git a/lua/nvim-lsp-installer/installers/shell.lua b/lua/nvim-lsp-installer/installers/shell.lua index bfdb5dea..98f12103 100644 --- a/lua/nvim-lsp-installer/installers/shell.lua +++ b/lua/nvim-lsp-installer/installers/shell.lua @@ -1,11 +1,8 @@ -local M = {} +local installers = require "nvim-lsp-installer.installers" -local default_opts = { - prefix = "set -euo pipefail;", -} +local M = {} -function M.raw(raw_script, opts) - opts = opts or {} +local function termopen(opts) return function(server, callback) local jobstart_opts = { cwd = server._root_dir, @@ -18,22 +15,61 @@ function M.raw(raw_script, opts) end, } - if type(opts.env) == "table" and vim.tbl_count(opts.env) then + if type(opts.env) == "table" and vim.tbl_count(opts.env) > 0 then -- passing an empty Lua table causes E475, for whatever reason jobstart_opts.env = opts.env end - local shell = vim.o.shell - vim.o.shell = "/bin/bash" + local orig_shell = vim.o.shell + vim.o.shell = opts.shell vim.cmd [[new]] - vim.fn.termopen((opts.prefix or default_opts.prefix) .. raw_script, jobstart_opts) - vim.o.shell = shell + vim.fn.termopen(opts.cmd, jobstart_opts) + vim.o.shell = orig_shell vim.cmd [[startinsert]] -- so that we tail the term log nicely ¯\_(ツ)_/¯ end end -function M.remote(url, opts) - return M.raw(("wget -nv -O - %q | bash"):format(url), opts) +function M.bash(raw_script, opts) + local default_opts = { + prefix = "set -euo pipefail;", + env = {}, + } + opts = vim.tbl_deep_extend("force", default_opts, opts or {}) + + return termopen { + shell = "/bin/bash", + cmd = (opts.prefix or "") .. raw_script, + env = opts.env, + } +end + +function M.remote_bash(url, opts) + return M.bash(("wget -nv -O - %q | bash"):format(url), opts) +end + +function M.cmd(raw_script, opts) + local default_opts = { + env = {}, + } + opts = vim.tbl_deep_extend("force", default_opts, opts or {}) + + return termopen { + shell = "cmd.exe", + cmd = raw_script, + env = opts.env, + } +end + +function M.polyshell(raw_script, opts) + local default_opts = { + env = {}, + } + opts = vim.tbl_deep_extend("force", default_opts, opts or {}) + + return installers.when { + unix = M.bash(raw_script, { env = opts.env }), + win = M.cmd(raw_script, { env = opts.env }), + } end return M |
