vim-settings/neovim/lua/init.lua

78 lines
2.5 KiB
Lua
Raw Normal View History

2021-08-24 16:55:37 +00:00
local o, wo, bo = vim.o, vim.wo, vim.bo
-- Helpers
2021-08-24 17:38:14 +00:00
require "_settings"
require "_bindings"
utils = require("utils")
2021-08-24 16:55:37 +00:00
-- Modify visual presentation
-- Create commands
vim.cmd "command! TagsUpdate !ctags -R ."
vim.cmd "command! Todo grep TODO"
-- Use better grep programs
if vim.fn.executable('rg') == 1 then
vim.o.grepprg = "rg --vimgrep --no-heading --color=never"
vim.o.grepformat = "%f:%l:%c:%m,%f:%l:%m"
elseif vim.fn.executable('ag') == 1 then
vim.o.grepprg = "ag --vimgrep --nogroup --nocolor"
elseif vim.fn.executable('ack') == 1 then
vim.o.grepprg = "ack"
end
-- TODO: Determine if I want to keep this or remove it in favor of dark-notify
_G.update_colors = function()
local function maybe_set(scope, name, val)
if vim[scope][name] ~= val then
vim[scope][name] = val
return true
end
return false
end
-- Set colorscheme based on env
local default_color = "solarized"
2021-08-24 17:38:14 +00:00
local env_color = utils.env_default("VIM_COLOR", default_color)
2021-08-24 16:55:37 +00:00
-- Read dark mode
local mode = vim.env.IS_DARKMODE
2021-08-24 16:55:37 +00:00
if vim.g.is_mac == 1 then
cmd = "defaults read -g AppleInterfaceStyle 2>/dev/null || echo Light"
mode = vim.fn.system(cmd):gsub("\n", ""):lower()
2021-08-24 16:55:37 +00:00
end
-- Update background and theme
2021-08-24 16:55:37 +00:00
local change = false
if mode == "dark" then
2021-08-24 17:38:14 +00:00
env_color = utils.env_default("VIM_COLOR_DARK", env_color)
2021-08-24 16:55:37 +00:00
change = maybe_set("o", "background", "dark")
change = maybe_set("g", "colors_name", env_color) or change
elseif mode == "light" then
2021-08-24 17:38:14 +00:00
env_color = utils.env_default("VIM_COLOR_LIGHT", env_color)
2021-08-24 16:55:37 +00:00
change = maybe_set("o", "background", "light")
change = maybe_set("g", "colors_name", env_color) or change
end
-- Update status line theme
2021-08-24 16:55:37 +00:00
if change and vim.fn.exists(":AirlineRefresh") == 1 then
vim.cmd(":AirlineRefresh")
elseif change and _G["packer_plugins"] ~= nil and packer_plugins["lualine"] and packer_plugins["lualine"].loaded then
local lualine_theme = vim.g.colors_name
if lualine_theme == "solarized" then
lualine_theme = lualine_theme .. "_" .. mode
end
require("plugins.lualine").config_lualine(lualine_theme)
2021-08-24 16:55:37 +00:00
end
return changed and "Changed color to " .. env_color .. " with mode " .. mode or "No change"
2021-08-24 16:55:37 +00:00
end
2021-08-24 17:38:14 +00:00
-- utils.autocmd("auto_colors", "FocusGained * call v:lua.update_colors()")
2021-08-24 16:55:37 +00:00
-- Initial set of colors
-- TODO: if update_colors() is removed, use the env color fetching and set the colorscheme here
update_colors()
2021-08-24 17:38:14 +00:00
require("plugins")