summaryrefslogtreecommitdiffstats
path: root/.config/nvim/lua/utils.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/utils.lua')
-rwxr-xr-x.config/nvim/lua/utils.lua46
1 files changed, 46 insertions, 0 deletions
diff --git a/.config/nvim/lua/utils.lua b/.config/nvim/lua/utils.lua
new file mode 100755
index 0000000..ae164e8
--- /dev/null
+++ b/.config/nvim/lua/utils.lua
@@ -0,0 +1,46 @@
+local utils = {}
+
+local scopes = {o = vim.o, b = vim.bo, w = vim.wo}
+
+--- Apply a setting with a specified scope
+function utils.opt(scope, key, value)
+ scopes[scope][key] = value
+ if scope ~= 'o' then scopes['o'][key] = value end
+end
+
+--- Apply an array of settings
+function utils.opts(params)
+ for i, item in ipairs(params) do
+ utils.opt(item[1], item[2], item[3])
+ end
+end
+
+--- Key mapping
+function utils.map(mode, lhs, rhs, opts)
+ local options = {noremap = true}
+ if opts then options = vim.tbl_extend('force', options, opts) end
+ vim.api.nvim_set_keymap(mode, lhs, rhs, options)
+end
+
+function utils.get_python_venv()
+ local lsputil = require('lspconfig/util')
+ local match
+
+ if vim.env.VIRTUAL_ENV then
+ return vim.env.VIRTUAL_ENV
+ end
+
+ match = vim.fn.glob(lsputil.path.join(vim.fn.getcwd(), 'Pipfile'))
+ if match ~= '' then
+ return vim.fn.trim(vim.fn.system('PIPENV_PIPFILE=' .. match .. ' pipenv --venv'))
+ end
+
+ match = vim.fn.system('test -f poetry.lock && poetry env info -p')
+ if vim.v.shell_error then
+ return vim.fn.trim(match)
+ end
+
+ return ''
+end
+
+return utils
remember that computers suck.