#!/bin/bash
# BlueRune's Neovim: Neovim with BlueRune's config (/usr/share/bluerune/nvim), and its own
# plugins, data and state (NVIM_APPNAME=bluerune-nvim), so ~/.config/nvim is never read or
# written.
#
#   bluerune-nvim [file…]                             in the terminal
#   bluerune-nvim --gui [file…] [-- neovim-option…]   in a Neovide window (the "Neovim" app)
export NVIM_APPNAME=bluerune-nvim
config=/usr/share/bluerune/nvim/init.lua
if [[ $1 == --gui ]]; then
  shift
  # Neovide opens the files itself; Neovim's own options go after its --.
  files=() options=()
  while (($#)); do
    if [[ $1 == -- ]]; then
      shift
      options=("$@")
      break
    fi
    files+=("$1")
    shift
  done
  exec neovide "${files[@]}" -- -u "$config" "${options[@]}"
fi
exec nvim -u "$config" "$@"
