Browse Source

feat: allow storing configurations in other path, see #79

my-config
NTBBloodbath 3 years ago
parent
commit
e21b84ffb9
No known key found for this signature in database GPG Key ID: 18D6730BC846AAC5
  1. 28
      docs/faq.md
  2. 16
      lua/doom/core/config/doomrc.lua
  3. 19
      lua/doom/core/config/init.lua
  4. 16
      lua/doom/extras/logging/init.lua
  5. 8
      lua/doom/modules/init.lua
  6. 26
      lua/doom/utils/init.lua

28
docs/faq.md

@ -15,3 +15,31 @@ Doom Nvim doesn't support Neovim versions lower than the current stable (0.5) du
- Not all Lua plugins have good alternatives in Vimscript, so the experience
would not be the same
- performance would not be the same as Lua cannot be used
### How to version control Doom Nvim?
Doom Nvim makes use of an internal variable called `doom_configs_root` that points
to `/home/user/.config/doom-nvim` path by default. This allows you to move your
configuration files to this path so you can version control your doom setup too.
> **NOTE**: In case that you're using cheovim (with `/home/user/.config/doom-nvim`
> as your Doom Nvim path) then you will need to change this variable value manually
> by tweaking [this](../lua/doom/utils/init.lua) file.
After changing your configurations path you will surely want to remove your
`~/.config/nvim/plugin/packer_compiled.lua` and running `:PackerCompile` again.
Also you will need to create a symlink from your new path to the old one for
avoiding issues when updating Doom Nvim. Here is a snippet for this task.
```sh
# Change this variable path if you have installed Doom Nvim in other place
DOOM_ROOT="${XDG_CONFIG_HOME:-$HOME/.config}/nvim"
# Change this variable path if you have changed the Doom Nvim doom_configs_root variable
DOOM_CONFIG_ROOT="${XDG_CONFIG_HOME:-$HOME/.config}/doom-nvim"
# Let's iterate over the configurations path directory files and create a symlink for them
for _config_file in $(ls "$DOOM_CONFIG_ROOT"); do
ln -s "${DOOM_CONFIG_ROOT}/$_config_file" "${DOOM_ROOT}/$_config_file"
done
```

16
lua/doom/core/config/doomrc.lua

@ -82,13 +82,21 @@ end
-- load_doomrc Loads the doomrc if it exists, otherwise it'll fallback to doom
-- default configs.
M.load_doomrc = function()
local config
local config, doomrc_path
-- /home/user/.config/doom-nvim/doomrc
if vim.fn.filereadable(utils.doom_root .. "/doomrc.lua") == 1 then
-- Path cases:
-- 1. /home/user/.config/doom-nvim/doomrc.lua
-- 2. /home/user/.config/nvim/doomrc.lua
if utils.file_exists(utils.doom_configs_root .. "/doomrc.lua") then
doomrc_path = utils.doom_configs_root .. "/doomrc.lua"
elseif utils.file_exists(utils.doom_root .. "/doomrc.lua") then
doomrc_path = utils.doom_root .. "/doomrc.lua"
end
if doomrc_path then
local loaded_doomrc, err = pcall(function()
log.debug("Loading the doomrc file ...")
config = dofile(utils.doom_root .. "/doomrc.lua")
config = dofile(doomrc_path)
end)
if not loaded_doomrc then

19
lua/doom/core/config/init.lua

@ -396,14 +396,23 @@ M.load_config = function()
doom = {},
nvim = {},
}
local doom_config_path
-- Path cases:
-- 1. /home/user/.config/doom-nvim/doom_config.lua
-- 2. /home/user/.config/nvim/doom_config.lua
if utils.file_exists(utils.doom_configs_root .. "/doom_config.lua") then
doom_config_path = utils.doom_configs_root .. "/doom_config.lua"
elseif utils.file_exists(utils.doom_root .. "/doom_config.lua") then
doom_config_path = utils.doom_root .. "/doom_config.lua"
end
-- /home/user/.config/doom-nvim/doomrc
if vim.fn.filereadable(utils.doom_root .. "/doom_config.lua") == 1 then
local loaded_doomrc, err = pcall(function()
config = dofile(utils.doom_root .. "/doom_config.lua")
if doom_config_path then
local loaded_doom_config, err = pcall(function()
config = dofile(doom_config_path)
end)
if not loaded_doomrc then
if not loaded_doom_config then
log.error("Error while loading the doom_config file. Traceback:\n" .. err)
end
else

16
lua/doom/extras/logging/init.lua

@ -9,7 +9,19 @@
----- CUSTOM SECTION --------------------------------------
-----------------------------------------------------------
local utils = require("doom.utils")
local doom_config = dofile(utils.doom_root .. "/doom_config.lua")
-- logging defaults to "info" level
local doom_config = {
doom = {
logging = "info",
},
}
-- /home/user/.config/doom-nvim/doom_config.lua
if utils.file_exists(utils.doom_root .. "/doom_config.lua") then
doom_config = dofile(utils.doom_root .. "/doom_config.lua")
elseif utils.file_exists(utils.doom_configs_root .. "/doom_config.lua") then
doom_config = dofile(utils.doom_configs_root .. "/doom_config.lua")
end
-----------------------------------------------------------
-----------------------------------------------------------
@ -30,7 +42,7 @@ local default_config = {
-- Any messages above this level will be logged.
-- defaults to info
level = (doom_config.doom.logging == nil and "info" or doom_config.doom.logging),
level = doom_config.doom.logging,
-- Level configuration
modes = {

8
lua/doom/modules/init.lua

@ -452,7 +452,13 @@ packer.startup(function(use)
--- Custom Plugins ---
-----]]----------------[[-----
-- If there are custom plugins then also require them
local custom_plugins = dofile(utils.doom_root .. "/plugins.lua")
local custom_plugins = {}
if utils.file_exists(utils.doom_configs_root) then
custom_plugins = dofile(utils.doom_configs_root .. "/plugins.lua")
else
custom_plugins = dofile(utils.doom_root .. "/plugins.lua")
end
for _, plug in pairs(custom_plugins) do
packer.use(plug)
end

26
lua/doom/utils/init.lua

@ -10,13 +10,19 @@ local M = {}
-- Doom Nvim version
M.doom_version = "3.1.0"
-- Local files
-- Get the user config directory, e.g. '/home/JohnDoe/.config'
local config_dir = os.getenv("XDG_CONFIG_HOME") and os.getenv("XDG_CONFIG_HOME")
or os.getenv("HOME") .. "/.config"
-- The doom-nvim root directory
M.doom_root = string.format("%s/nvim", config_dir)
-- The doom-nvim configurations root directory
M.doom_configs_root = string.format("%s/doom-nvim", config_dir)
-- The doom-nvim logs file path
M.doom_logs = vim.fn.stdpath("data") .. "/doom.log"
-- The doom-nvim bug report file path
M.doom_report = vim.fn.stdpath("data") .. "/doom_report.md"
-- The git workspace for doom-nvim, e.g. 'git -C /home/JohnDoe/.config/nvim'
M.git_workspace = string.format("git -C %s ", M.doom_root)
-- Mappings wrapper, extracted from
@ -86,7 +92,7 @@ M.create_augroups = function(definitions)
end
-- Check if string is empty or if it's nil
-- @return bool
-- @return boolean
M.is_empty = function(str)
return str == "" or str == nil
end
@ -104,6 +110,7 @@ M.has_value = function(tabl, val)
end
-- Get current OS, returns 'Other' if the current OS is not recognized
-- @return string
M.get_os = function()
--[[
-- Target OS names:
@ -119,6 +126,19 @@ M.get_os = function()
return jit.os
end
-- file_exists checks if the given file exists
-- @tparam string path The path to the file
-- @return boolean
M.file_exists = function(path)
local fd = vim.loop.fs_open(path, "r", 438)
if fd then
vim.loop.fs_close(fd)
return true
end
return false
end
-- read_file returns the content of the given file
-- @tparam string path The path of the file
-- @return string

Loading…
Cancel
Save