Last active
June 12, 2022 14:59
-
-
Save GaussianWonder/6b0c44605df7a51ea9cbe90f68f7849c to your computer and use it in GitHub Desktop.
Start LunarVim in Neovide while still being able to pass arguments to each instance individually. Arguments are separated by "--". First half of the arguments are vim arguments, the other half are neovide arguments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# find index of $1 in [$2 $3 $4 ...] | |
function indexof { | |
search="$1"; shift | |
i=0 | |
for arg; do | |
if [ "$search" = "$arg" ] | |
then | |
echo $i | |
return 0 | |
fi | |
((i++)) | |
done | |
return 255 | |
} | |
# find index of "--" in the list of arguments | |
arg_split_index=$(indexof "--" $@) | |
# if not present, all args are neovide args | |
if [ $? -eq 255 ] | |
then | |
arg_split_index=$# | |
fi | |
# Split array of args in two | |
left_args_i=0 | |
left_args_len=$((arg_split_index)) | |
right_args_i=$(($left_args_i+$left_args_len+1)) | |
right_args_len=$(($#-$left_args_len-1)) | |
# Take into account the $0 | |
vim_args=${@:$(($left_args_i+1)):$left_args_len} | |
neovide_args=${@:$(($right_args_i+1)):$right_args_len} | |
# Default arguments for vim | |
# if [ $left_args_len -eq -1 ] | |
# then | |
# vim_args="" | |
# fi | |
# Default arguments for neovide | |
if [ $right_args_len -eq -1 ] | |
then | |
neovide_args="--multigrid" | |
fi | |
echo "Neovide args: $neovide_args" | |
echo "Vim args: $vim_args" | |
# Prepare to launch LunarVim inside Neovide with arguments for each process | |
export LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-"$HOME/.local/share/lunarvim"}" | |
export LUNARVIM_CONFIG_DIR="${LUNARVIM_CONFIG_DIR:-"$HOME/.config/lvim"}" | |
export LUNARVIM_CACHE_DIR="${LUNARVIM_CACHE_DIR:-"$HOME/.cache/lvim"}" | |
exec neovide ${neovide_args[@]} -- -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" ${vim_args[@]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment