AstroNvim / docs

Site for AstroNvim
https://docs.astronvim.com
23 stars 60 forks source link

Add reference page for separate installation from base Neovim using `NVIM_APPNAME` #12

Closed mehalter closed 10 months ago

mehalter commented 2 years ago

https://github.com/AstroNvim/AstroNvim/issues/634

Add reference page for users to have an installation similar to how LunarVim does things with a avim command in the users path

osamuaoki commented 2 years ago

Hi,

As for installing AstroNvim off normal nvim runtimepath, we can document as follows:

$ mkdir -p ~/.config/avim
$ git clone   https://github.com/AstroNvim/AstroNvim.git ~/.config/avim
$ cat ~/bin/avim <<"EOF"
#!/bin/sh -e
# set up an alternative work environment
AVIM_PREFIX="avim"
XDG_CONFIG_HOME="$HOME/.config/$AVIM_PREFIX"
XDG_DATA_HOME="$HOME/.local/share/$AVIM_PREFIX"
NVIM_LOG_FILE="$HOME/.cache/$AVIM_PREFIX/log"
mkdir -p "$XDG_CONFIG_HOME"
mkdir -p "$XDG_DATA_HOME"
mkdir -p "${NVIM_LOG_FILE%/*}"
export XDG_CONFIG_HOME XDG_DATA_HOME NVIM_LOG_FILE
echo "$XDG_CONFIG_HOME"
echo "$XDG_DATA_HOME"
echo "${NVIM_LOG_FILE%/*}"
exec nvim "$@"
# vim:set ai et sw=2 ts=2 sts=2 tw=80:
EOF
$ chmod 755 ~/bin/avim
$ avim

In principle, the rest should be normal with file locations changed. (I assumed ~/bin is in $PATH)

At least, this is cleaner solution following exposed environment variables. (NO strange variables exported.)

The thing is I haven't used much. I don't know how some plugins are not well behaving. This needs to be tested.

osamuaoki commented 2 years ago

I realize, having multiple independent set-up is quite convenient, I whiped up an simple shell script. In order not to loose it, I am pasting it here. I now can have avi0 avi1, avi3, ... ;-)

#!/bin/sh -e
# AstroNvim installer for Unix-like environment
URL_GITHUB="https://github.com/AstroNvim/AstroNvim.git"
if [ -z "$1" ]; then
  echo "If you wish to create a name for NeoVim command as '<name>',"
  echo "Please run this program as '${0##*} <name>' ."
  exit 1
fi
NVIM_NAME="$1"
cd >/dev/null || true
HOME=$(pwd)
mkdir -p "$HOME/bin"
if [ -e "$HOME/bin/$NVIM_NAME" ]; then
  echo "$HOME/bin/$NVIM_NAME file(?) aleady exists.  Remove it first."
  exit 1
fi
if [ -e "$HOME/.config/$NVIM_NAME" ]; then
  echo "$HOME/.config/$NVIM_NAME directory(?) aleady exists.  Remove it first."
  exit 1
fi
if [ -e "$HOME/.local/share/$NVIM_NAME" ]; then
  echo "$HOME/.local/share/$NVIM_NAME directory(?) aleady exists.  Remove it first."
  exit 1
fi
if [ -e "$HOME/.cache/$NVIM_NAME" ]; then
  echo "$HOME/.cache/$NVIM_NAME directory(?) aleady exists.  Remove it first."
  exit 1
fi
# No preexisting installations, let's start
if [ "$NVIM_NAME" = "nvim" ]; then
  echo "Basic installation"
  mkdir -p "$HOME/.config"
  git clone "$URL_GITHUB" "$HOME/.config/nvim"
  mkdir -p "$HOME/.local/share/nvim"
  mkdir -p "$HOME/.cache"
else
  echo "Offset installation"
  mkdir -p "$HOME/.config/$NVIM_NAME"
  git clone "$URL_GITHUB" "$HOME/.config/$NVIM_NAME/nvim"
  mkdir -p "$HOME/.local/share/$NVIM_NAME/nvim"
  mkdir -p "$HOME/.cache/$NVIM_NAME"
cat > "$HOME/bin/$NVIM_NAME" << "EOF"
#!/bin/sh -e
# set up an alternative work environment for nvim
NVIM_NAME="${0##*/}"
XDG_CONFIG_HOME="$HOME/.config/$NVIM_NAME"
XDG_DATA_HOME="$HOME/.local/share/$NVIM_NAME"
NVIM_LOG_FILE="$HOME/.cache/$NVIM_NAME/log"
export XDG_CONFIG_HOME XDG_DATA_HOME NVIM_LOG_FILE
# shellcheck disable=SC2093
exec nvim "$@"
EOF
chmod 755 "$HOME/bin/$NVIM_NAME"
fi
# vim:set ai et sw=2 ts=2 sts=2 tw=80:
windowsrefund commented 2 years ago

This seems overly complicated and something that would never catch on. One of the reasons Astronvim is so nice is due to the fact it will look for override configs in ~/.config/astronvim/lua/user. As for multiple versions, I'm of the opinion that user config directory should just be managed as a git repo where you can test features in a feature branch as needed. That's a smarter and more efficient way to work than maintaining who knows how many copies of mostly redundant directories named $foo1, $foo2, etc, etc....

In summary, everything is already there in order to maintain a wall between the core files and the user config. If any automation were to be added, I'd think it's only purpose would be to setup a skeleton user config directory. There should be no need to throw anything into a user's ~/bin directory or stuff like that either.

osamuaoki commented 2 years ago

I am a bit surprised by somewhat harsh criticism. But is it true?

I know and I use ~/.config/astronvim/lua/user. But that doesn't give us what OP said "Add recipe for users to have an installation similar to how LunarVim does things". They are meant for different usage cases.

LunarVim used to do quite intrusive vim RTP modification to do what it does. But now that NeoVim properly support XDG Base Directory Specification, we can use it now.

The script above is meant to be simpler approach by avoiding to make a exact replica of LunarVim script with the same file placement. (I also didn't use getopt nor trap to keep code simple.)

Having avim configured independently from the standard one installed in ~/.config/nvim/. and ~/.config/astronvim/ combination is useful. Configuration for avim as proposed above uses configuration in ~/.config/avim/nvim/. and ~/.config/avim/astronvim/ combination by setting XDG environment variable.

As for PR https://github.com/AstroNvim/AstroNvim/pull/813 The script is made to be a bit more generic. So any good XDG repecting configuration setup such as NvChad can use this. (But not LunarVim)

VonHeikemen commented 1 year ago

I made this lua script that can isolate AstroNvim environment, if used as an entrypoint it will allow you to have a config for AstroNvim and also a personal config for Neovim.

local path_sep = vim.loop.os_uname().version:match('Windows') and '\\' or '/'
local join = function(...) return table.concat({...}, path_sep) end
local getpath = function(arg)
  local path = vim.fn.stdpath(arg)
  return vim.fn.substitute(path, [[\(.*\)\zsnvim]], 'astronvim', '')
end

local data_path = getpath('data')
local astro_config = join(data_path, 'core')
local user_path = getpath('config')

vim.env.XDG_DATA_HOME = data_path
vim.env.XDG_CACHE_HOME = join(data_path, 'cache')
vim.env.XDG_STATE_HOME = join(data_path, 'state')

vim.opt.runtimepath = {
  user_path,
  astro_config,
  vim.env.VIMRUNTIME,
  join(astro_config, 'after'),
  join(user_path, 'after'),
}

vim.opt.packpath = {
  join(data_path, 'nvim', 'site'),
  user_path,
  vim.env.VIMRUNTIME
}

astronvim_installation = {home = astro_config}

local execute = loadfile(join(astro_config, 'init.lua'))

if not execute then
  vim.api.nvim_err_writeln("Could not load AstroNvim's init.lua")
  return
end

execute()
git clone https://github.com/AstroNvim/AstroNvim ~/.local/share/astronvim/core
mkdir -p ~/.config/astronvim
~/.config/astronvim/entry.lua
alias code='nvim -u ~/.config/astronvim/entry.lua'
mehalter commented 1 year ago

I think we should put this in the documentation using the new NVIM_APPNAME feature that comes with Neovim v0.9 since that is the core neovim feature for doing this rather than us providing an arbitrary script.

mehalter commented 10 months ago

Added in latest commit to v4 branch