๐Ÿ“ฆ SergioRibera / cmp-dotenv

cmp import and use all environment variables from .env.* and system

โ˜… 92 stars โ‘‚ 0 forks ๐Ÿ‘ 92 watching โš–๏ธ GNU General Public License v2.0
luaneovimneovim-pluginnixnvim-cmpnvim-plugin
๐Ÿ“ฅ Clone https://github.com/SergioRibera/cmp-dotenv.git
HTTPS git clone https://github.com/SergioRibera/cmp-dotenv.git
SSH git clone git@github.com:SergioRibera/cmp-dotenv.git
CLI gh repo clone SergioRibera/cmp-dotenv
Sergio Alejandro Ribera Costa Sergio Alejandro Ribera Costa Merge pull request #4 from mostafaqanbaryan/main 4dd53aa 1 years ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ .github
๐Ÿ“ after
๐Ÿ“ lua
๐Ÿ“ nix
๐Ÿ“ spec
๐Ÿ“„ .busted
๐Ÿ“„ .editorconfig
๐Ÿ“„ .envrc
๐Ÿ“„ .gitignore
๐Ÿ“„ .luacheckrc
๐Ÿ“„ .stylua.toml
๐Ÿ“„ CHANGELOG.md
๐Ÿ“„ CONTRIBUTING.md
๐Ÿ“„ default.nix
๐Ÿ“„ flake.lock
๐Ÿ“„ flake.nix
๐Ÿ“„ LICENSE
๐Ÿ“„ README.md
๐Ÿ“„ shell.nix
๐Ÿ“„ README.md

cmp-dotenv

https://github.com/SergioRibera/cmp-dotenv/assets/56278796/8a23c17a-6f08-45db-b567-de47cd9a8a81

Wihtout cmp-dotenvWith cmp-dotenv
imageimage

The plugin you need to have an autocomplete of the environment variables of your system and those of your .env* files

[!IMPORTANT]
This repository does not require constant updates but if you have any problems or feature suggestions open an issue and I will be happy to check it out.

Setup

require("cmp").setup {
    sources = {
        { name = "dotenv" }
    }
}

Or with configuration

local cmp = require("cmp")

cmp.setup {
    sources = {
        {
          name = "dotenv",
          -- Defaults
          option = {
            path = '.',
            load_shell = true,
            item_kind = cmp.lsp.CompletionItemKind.Variable,
            eval_on_confirm = false,
            show_documentation = true,
            show_content_on_docs = true,
            documentation_kind = 'markdown',
            dotenv_environment = '.*',
            file_priority = function(a, b)
              -- Prioritizing local files
              return a:upper() < b:upper()
            end,
          }
        }
    }
}

Options

namedefaultdescription
path'.'The path where to look for the files
loadshelltrueDo you want to load shell variables?
itemkindVariableWhat kind of suggestion will cmp make?
evalonconfirmfalseWhen you confirm the completion, do you want the variable or the value?
showdocumentationtrueDo you want to see the documentation that has the variable?
showcontentondocstrueAllows to preview the content in the documentation popup with the prefix of Content: .
documentationkind'markdown'What did you write the variable documentation on?
dotenvenvironment'.*'Which variable environment do you want to load? .* by default loads all of them, this variable accepts regex, some suggestions I can give you are example, local or development.
file_priorityfunctionWith this function you define the upload priority, by default it prioritizes the local variables, this responds to the callback of a computer for the found files.

Advanced Usage

If you are a developer or just want to do more things in your lua configuration, you can use the api provided here and the (recommended) functions available, are these

local dotenv = require('cmp-dotenv.dotenv')

-- Get the variable you want by name or
-- get the default value in case it does not exist.
dotenv.get_env_variable(name, default)

-- Get all variables that have been loaded
dotenv.get_all_env()

-- You can set a variable to the auto-completion system and
-- find it available throughout the Neovim environment.
-- You can pass it a documentation in the format
-- you have configured or not pass it at all.
dotenv.set_env_variable(name, value, docs or nil)

-- This loads all the environment variables according to the
-- configuration you have from the files or the shell,
-- I do not recommend calling this function as it is
-- usually called by default by cmp.
dotenv.load(force, options)

Contributing

All contributions are welcome! See CONTRIBUTING.md.

License

This template is licensed according to GPL version 2, with the following exception:

The license applies only to the Nix CI infrastructure provided by this template repository, including any modifications made to the infrastructure. Any software that uses or is derived from this template may be licensed under any OSI approved open source license, without being subject to the GPL version 2 license of this template.