3rd party Neovim plugin that compliments https://mise.jdx.dev/

Initial commit

ejrichards 6e4e8a85

Changed files
+303
.github
workflows
doc
lua
+37
.github/workflows/ci.yml
··· 1 + name: CI 2 + on: 3 + push: 4 + branches: 5 + - 'master' 6 + pull_request: 7 + branches: 8 + - 'master' 9 + 10 + jobs: 11 + docs: 12 + runs-on: ubuntu-latest 13 + steps: 14 + - uses: actions/checkout@v4 15 + - name: panvimdoc 16 + uses: kdheepak/panvimdoc@v4.0.1 17 + with: 18 + vimdoc: mise.nvim 19 + version: "Neovim >= 0.9.0" 20 + demojify: true 21 + treesitter: true 22 + - name: Push changes 23 + uses: stefanzweifel/git-auto-commit-action@v5 24 + with: 25 + commit_message: "chore(build): auto-generate vimdoc" 26 + commit_user_name: "github-actions[bot]" 27 + commit_user_email: "github-actions[bot]@users.noreply.github.com" 28 + commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>" 29 + release: 30 + name: release 31 + needs: 32 + - docs 33 + runs-on: ubuntu-latest 34 + steps: 35 + - uses: googleapis/release-please-action@v4 36 + with: 37 + release-type: simple
+2
.gitignore
··· 1 + .mise.local.toml 2 + /testdata
+21
LICENSE
··· 1 + MIT License 2 + 3 + Copyright (c) 2024 ejrichards 4 + 5 + Permission is hereby granted, free of charge, to any person obtaining a copy 6 + of this software and associated documentation files (the "Software"), to deal 7 + in the Software without restriction, including without limitation the rights 8 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 + copies of the Software, and to permit persons to whom the Software is 10 + furnished to do so, subject to the following conditions: 11 + 12 + The above copyright notice and this permission notice shall be included in all 13 + copies or substantial portions of the Software. 14 + 15 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 + SOFTWARE.
+42
README.md
··· 1 + # mise.nvim 2 + 3 + mise.nvim is a 3rd party Neovim plugin that compliments [mise](https://mise.jdx.dev/) by setting the environment variables when `:cd`-ing inside Neovim or using a GUI like [Neovide](https://neovide.dev/). If you run Neovim from a terminal and don't regularly use `:cd`, you probably don't need this plugin. 4 + 5 + ## Setup 6 + 7 + lazy.nvim 8 + ```lua 9 + { 10 + "ejrichards/mise.nvim", 11 + opts = {} 12 + } 13 + ``` 14 + 15 + ## Configuration 16 + 17 + Defaults 18 + ```lua 19 + { 20 + -- Executable to run and the args to pass 21 + run = 'mise', 22 + args = 'env --json', 23 + -- Set to override the base PATH 24 + initial_path = vim.env.PATH, 25 + -- Removes env vars set by mise when navigating away from a directory 26 + unset_vars = true, 27 + -- Loads env vars when setup() is called, don't need this if mise is hooked into your shell 28 + load_on_setup = true, 29 + -- Force a run when using an unsupported executable 30 + force_run = false, 31 + } 32 + ``` 33 + 34 + ## Commands 35 + 36 + - `:Mise` - Print vars for pwd 37 + 38 + ## Limitations 39 + 40 + The base path will be the `$PATH` env var on load. If Neovim launched from the shell where mise has already loaded some paths, this plugin cannot distinguish which parts of the path were loaded by mise, so they will always be included. This can be overridden using the `initial_path` in the setup config if you run into issues. 41 + 42 + TODO: Test whether mise will deal with this case correctly
doc/.gitkeep

This is a binary file and will not be displayed.

+72
doc/mise.nvim.txt
··· 1 + *mise.nvim.txt* For Neovim >= 0.9.0 Last change: 2024 June 19 2 + 3 + ============================================================================== 4 + Table of Contents *mise.nvim-table-of-contents* 5 + 6 + 1. mise.nvim |mise.nvim-mise.nvim| 7 + - Setup |mise.nvim-mise.nvim-setup| 8 + - Configuration |mise.nvim-mise.nvim-configuration| 9 + - Commands |mise.nvim-mise.nvim-commands| 10 + - Limitations |mise.nvim-mise.nvim-limitations| 11 + 12 + ============================================================================== 13 + 1. mise.nvim *mise.nvim-mise.nvim* 14 + 15 + mise.nvim is a 3rd party Neovim plugin that compliments mise 16 + <https://mise.jdx.dev/> by setting the environment variables when `:cd`-ing 17 + inside Neovim or using a GUI like Neovide <https://neovide.dev/>. If you run 18 + Neovim from a terminal and don’t regularly use `:cd`, you probably don’t 19 + need this plugin. 20 + 21 + 22 + SETUP *mise.nvim-mise.nvim-setup* 23 + 24 + lazy.nvim 25 + 26 + >lua 27 + { 28 + "ejrichards/mise.nvim", 29 + opts = {} 30 + } 31 + < 32 + 33 + 34 + CONFIGURATION *mise.nvim-mise.nvim-configuration* 35 + 36 + Defaults 37 + 38 + >lua 39 + { 40 + -- Executable to run and the args to pass 41 + run = 'mise', 42 + args = 'env --json', 43 + -- Set to override the base PATH 44 + initial_path = vim.env.PATH, 45 + -- Removes env vars set by mise when navigating away from a directory 46 + unset_vars = true, 47 + -- Loads env vars when setup() is called, don't need this if mise is hooked into your shell 48 + load_on_setup = true, 49 + -- Force a run when using an unsupported executable 50 + force_run = false, 51 + } 52 + < 53 + 54 + 55 + COMMANDS *mise.nvim-mise.nvim-commands* 56 + 57 + - `:Mise` - Print vars for pwd 58 + 59 + 60 + LIMITATIONS *mise.nvim-mise.nvim-limitations* 61 + 62 + The base path will be the `$PATH` env var on load. If Neovim launched from the 63 + shell where mise has already loaded some paths, this plugin cannot distinguish 64 + which parts of the path were loaded by mise, so they will always be included. 65 + This can be overridden using the `initial_path` in the setup config if you run 66 + into issues. 67 + 68 + TODO: Test whether mise will deal with this case correctly 69 + 70 + Generated by panvimdoc <https://github.com/kdheepak/panvimdoc> 71 + 72 + vim:tw=78:ts=8:noet:ft=help:norl:
+114
lua/mise/init.lua
··· 1 + local log = require("mise.log") 2 + 3 + local Mise = {} 4 + 5 + ---@class MiseConfig 6 + local defaults = { 7 + run = "mise", 8 + args = "env --json", 9 + initial_path = vim.env.PATH, 10 + unset_vars = true, 11 + load_on_setup = true, 12 + force_run = false, 13 + } 14 + 15 + ---@type MiseConfig 16 + local options 17 + 18 + local previous_vars = {} 19 + 20 + ---@param data table 21 + local function set_previous(data) 22 + previous_vars = {} 23 + for var_name, var_value in pairs(data) do 24 + if var_name ~= "PATH" then 25 + previous_vars[var_name] = var_value 26 + end 27 + end 28 + end 29 + 30 + ---@return table? 31 + local function get_data() 32 + local full_command = options.run .. " " .. options.args 33 + local env_sh = vim.fn.system(full_command) 34 + 35 + local ok, data = pcall(vim.json.decode, env_sh) 36 + if not ok or data == nil then 37 + log.error('Invalid json returned by "' .. full_command .. '"') 38 + return nil 39 + end 40 + 41 + return data 42 + end 43 + 44 + ---@param data table 45 + local function load_env(data) 46 + if options.unset_vars then 47 + for var_name, _ in pairs(previous_vars) do 48 + vim.env[var_name] = nil 49 + end 50 + end 51 + 52 + for var_name, var_value in pairs(data) do 53 + vim.env[var_name] = var_value 54 + end 55 + 56 + set_previous(data) 57 + end 58 + 59 + local function dir_changed() 60 + vim.env.PATH = options.initial_path 61 + 62 + local data = get_data() 63 + if data == nil then 64 + return 65 + end 66 + 67 + load_env(data) 68 + end 69 + 70 + ---@param opt? MiseConfig 71 + function Mise.setup(opt) 72 + options = vim.tbl_deep_extend("force", {}, defaults, opt or {}) 73 + 74 + if vim.fn.executable(options.run) ~= 1 then 75 + log.error('Cannot find "' .. options.run .. '" executable') 76 + return 77 + end 78 + 79 + if options.run ~= "mise" and not options.force_run then 80 + log.error(options.run .. ' not supported, set "force_run = true" in setup() if you know the data is correct.') 81 + return 82 + end 83 + 84 + local data = get_data() 85 + if data == nil then 86 + return 87 + end 88 + 89 + if options.load_on_setup then 90 + load_env(data) 91 + else 92 + set_previous(data) 93 + end 94 + 95 + 96 + local group = vim.api.nvim_create_augroup("mise.nvim", { clear = true }) 97 + vim.api.nvim_create_autocmd("DirChanged", { 98 + group = group, 99 + desc = "Run command to load env vars", 100 + callback = function() 101 + if vim.v.event.scope == "global" then 102 + dir_changed() 103 + end 104 + end, 105 + }) 106 + 107 + vim.api.nvim_create_user_command("Mise", function() 108 + log.info(vim.inspect(get_data())); 109 + end, { 110 + desc = "Mise", 111 + }) 112 + end 113 + 114 + return Mise
+15
lua/mise/log.lua
··· 1 + local log = {} 2 + 3 + function log.info(message) 4 + vim.notify("mise.nvim: " .. message, vim.log.levels.INFO, { title = "mise.nvim" }); 5 + end 6 + 7 + function log.warn(message) 8 + vim.notify("mise.nvim: " .. message, vim.log.levels.WARN, { title = "mise.nvim" }); 9 + end 10 + 11 + function log.error(message) 12 + vim.notify("mise.nvim: " .. message, vim.log.levels.ERROR, { title = "mise.nvim" }); 13 + end 14 + 15 + return log