diff --git a/home/.chezmoiscripts/universal/run_onchange_after_11-symlink-nvim.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_11-symlink-nvim.tmpl new file mode 100644 index 00000000..4a4cd03d --- /dev/null +++ b/home/.chezmoiscripts/universal/run_onchange_after_11-symlink-nvim.tmpl @@ -0,0 +1,30 @@ +{{- if (ne .host.distro.family "windows") -}} +#!/usr/bin/env bash +# @file Neovim Configuration +# @brief This script configures Neovim by applying the configuration stored in `${XDG_DATA_HOME:-$HOME/.config}/nvim-custom/init.lua` if the `nvim` application is available +# @description +# This script applies the Neovim configuration stored in `${XDG_DATA_HOME:-$HOME/.config}/nvim-custom/init.lua` if nvim is installed. +# The custom init configuration provides compatiblity between Volta and Neovim. This allows neovim to discover node modules installed by Volta. This script sets up +# init in such a way that the compatibility setting is applied even when Neovim is installed using Flatpak +# +# ## Links +# +# * [Default Neovim configuration](https://github.com/megabyte-labs/install.doctor/tree/master/home/dot_config/nvim-custom/init.lua) + +{{ includeTemplate "universal/profile" }} +{{ includeTemplate "universal/logg" }} + +### Symlink custom code for Neovim configuration +if [ ! -d "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/lua/custom" ]; then + logg info "Linking ${XDG_CONFIG_HOME:-$HOME/.config}/nvim-custom to ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/lua/custom" + logg info "Changes should go in ${XDG_CONFIG_HOME:-$HOME/.config}/nvim-custom" + ln -s "${XDG_CONFIG_HOME:-$HOME/.config}/nvim-custom" "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/lua/custom" +elif [ flatpak list | grep 'io.neovim.nvim' > /dev/null && ! -d "~/.var/app/io.neovim.nvim/config/nvim/lua/custom" ]; then + logg info "Linking ${XDG_CONFIG_HOME:-$HOME/.config}/nvim-custom to ~/.var/app/io.neovim.nvim/config/nvim/lua/custom" + logg info "Changes should go in ${XDG_CONFIG_HOME:-$HOME/.config}/nvim-custom" + ln -s "${XDG_CONFIG_HOME:-$HOME/.config}/nvim-custom" "~/.var/app/io.neovim.nvim/config/nvim/lua/custom" +else + logg info "${XDG_CONFIG_HOME:-$HOME/.config}/nvim-custom appears to already be symlinked to ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/lua/custom" +fi + +{{ end -}} diff --git a/home/dot_config/nvim-custom/init.lua b/home/dot_config/nvim-custom/init.lua index e7c0a38a..4113ca6d 100644 --- a/home/dot_config/nvim-custom/init.lua +++ b/home/dot_config/nvim-custom/init.lua @@ -1,3 +1,3 @@ if executable('volta') let g:node_host_prog = trim(system("volta which neovim-node-host")) -endif \ No newline at end of file +endif diff --git a/home/dot_config/shell/aliases.sh.tmpl b/home/dot_config/shell/aliases.sh.tmpl index bfb78608..c436ca44 100644 --- a/home/dot_config/shell/aliases.sh.tmpl +++ b/home/dot_config/shell/aliases.sh.tmpl @@ -73,6 +73,10 @@ if command -v vim > /dev/null; then alias vi='vim' alias v='vim' fi +### NVIM +if command -v nvim > /dev/null; then + alias nvim='env -u VIMINIT nvim' +fi ### mitmproxy / mitmweb if command -v mitmproxy > /dev/null; then diff --git a/home/dot_config/shell/profile.sh.tmpl b/home/dot_config/shell/profile.sh.tmpl index 01cc0af0..8809a117 100644 --- a/home/dot_config/shell/profile.sh.tmpl +++ b/home/dot_config/shell/profile.sh.tmpl @@ -136,3 +136,18 @@ fi ### VIM export GVIMINIT='let $MYGVIMRC="$XDG_CONFIG_HOME/vim/gvimrc" | source $MYGVIMRC' export VIMINIT='let $MYVIMRC="$XDG_CONFIG_HOME/vim/vimrc" | source $MYVIMRC' + +### NVIM +VIM_NEOVIM_INTEGRATION='vim.cmd([[ +set runtimepath^=~/.vim runtimepath+=~/.vim/after +let &packpath = &runtimepath +source ~/.vimrc +]])' +if command -v nvim > /dev/null && cat ~/.config/nvim/init.lua | grep 'set runtimepath^=~/.vim runtimepath+=~/.vim/after' > /dev/null; then + ### Setup Neovim to work with Vim setup and plugins + echo -e "$VIM_NEOVIM_INTEGRATION\n$(cat ~/.config/nvim/init.lua)" > ~/.config/nvim/init.lua || echo '' + if -d ~/.var/app/io.neovim.nvim/config/nvim; then + echo -e "$VIM_NEOVIM_INTEGRATION\n$(cat ~/.var/app/io.neovim.nvim/config/nvim/init.lua)" > ~/.var/app/io.neovim.nvim/config/nvim/init.lua || echo '' + fi +fi +unset VIM_NEOVIM_INTEGRATION