Dynamically toggle nvim configuration based on user profiles.
local uprofile = require("uprofile")
uprofile.setup()
You can set the profile using a environment variable. The default variable is NVIM_PROFILE
.
You can then add to your .bashrc the following line:
export NVIM_PROFILE=personal
and in another machine
export NVIM_PROFILE=work
In your nvim you can then toggle configuration like this:
local uprofile = require("uprofile")
uprofile.setup()
-- Install Plugins
packer.startup(function()
local use = use or use
use({ "wbthomason/packer.nvim" }) -- updates package manager
-- use onedark for personal and material for work
use({
uprofile.with_profile_table({
personal = "navarasu/onedark.nvim",
work = "marko-cerovac/material.nvim",
})
})
-- the above is similar to this:
uprofile.with_profile_fn("personal", function()
use({ "navarasu/onedark.nvim" })
end)
uprofile.with_profile_fn("work", function()
use({ "marko-cerovac/material.nvim"})
end)
-- or even:
user_profile.with_profile_fn("personal", use, { "navarasu/onedark.nvim" })
user_profile.with_profile_fn("work", use, { "marko-cerovac/material.nvim"})
end)
Another example is to conditionally enable different lsp servers based on the profile
local servers = user_profile.with_profile_table({
-- default profile is a fallback, if there is no match, `default` is returned
default = { "efm", "sumneko_lua", "tsserver", "eslint", "gopls", "clangd", "rust_analyzer", "pyright" },
work = { "efm", "sumneko_lua", "tsserver", "eslint" },
})
Example:
uprofile.setup({
-- if not set, this will be active
default_profile = "personal",
env_name = "NVIM_PROFILE",
})
Returns the current profile
Only executes fn
if profile_name
matches the the current profile
Example:
uprofile.with_profile_fn("work", function()
print("work profile is enabled")
end)
-- or
-- special `any` profile will run for all profiles
uprofile.with_profile_fn("any", function()
print(uprofile.get_active_profile(), " is enabled")
end)
index tbl
with the current active profile