| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Copyright (c) 2020-2021 shadmansaleh |
| 4 |
# MIT license, see LICENSE for more details. |
| 5 |
|
| 6 |
USAGE="Usage nvim_isolated_conf.sh [OPTIONS] Directory |
| 7 |
A tool to easily test isolated neovim config |
| 8 |
|
| 9 |
Options: |
| 10 |
-c Create a minimal config tree at Directory |
| 11 |
-e Edit init.vim of config in Directory |
| 12 |
-h Show this message |
| 13 |
-l Load neovim with config from Directory |
| 14 |
" |
| 15 |
|
| 16 |
INIT_TEMPLATE="call plug#begin(\"%s/.local/share/nvim/plugged\") |
| 17 |
\" Your plugins go here like |
| 18 |
Plug 'nvim-lualine/lualine.nvim' |
| 19 |
|
| 20 |
|
| 21 |
call plug#end() |
| 22 |
|
| 23 |
\" Your Viml part of config goes here |
| 24 |
\" colorscheme onedark |
| 25 |
|
| 26 |
|
| 27 |
lua << END |
| 28 |
-- Your lua part of config goes here |
| 29 |
require'lualine'.setup { |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
END |
| 35 |
|
| 36 |
\" Instructions: |
| 37 |
\" ------------------------------------------------------------- |
| 38 |
\" Load this config with nvim_isolated_conf.sh -l %s |
| 39 |
\" Remember to run :PlugInstall after changing plugin section |
| 40 |
\" Also delete the comments before putting this file on issue |
| 41 |
\" That will reduce noise |
| 42 |
\" You can delete %s once you're done" |
| 43 |
|
| 44 |
while getopts "c:e:hl:" arg; do |
| 45 |
case $arg in |
| 46 |
h) Help=true;; |
| 47 |
c) CreateDirInput=$OPTARG;; |
| 48 |
l) LoadDirInput=$OPTARG;; |
| 49 |
e) EditDirInput=$OPTARG;; |
| 50 |
esac |
| 51 |
done |
| 52 |
shift $((OPTIND -1)) |
| 53 |
|
| 54 |
|
| 55 |
if ! [ -z $LoadDirInput ];then |
| 56 |
LoadDir=$(realpath $LoadDirInput) |
| 57 |
if [ -d $LoadDir ];then |
| 58 |
export NVIM_CONFIG_HOME=$LoadDir |
| 59 |
export XDG_CONFIG_HOME=$NVIM_CONFIG_HOME/.config |
| 60 |
export XDG_DATA_HOME=$NVIM_CONFIG_HOME/.local/share |
| 61 |
export XDG_CACHE_HOME=$NVIM_CONFIG_HOME/.cache |
| 62 |
export XDG_STATE_HOME=$NVIM_CONFIG_HOME/.local/state |
| 63 |
nvim $@ |
| 64 |
else |
| 65 |
echo "Sorry can't load neovim config. ${LoadDir} doesn't exist" |
| 66 |
fi |
| 67 |
elif ! [ -z $CreateDirInput ];then |
| 68 |
CreateDir=$(realpath $CreateDirInput) |
| 69 |
echo "Creating directories" |
| 70 |
mkdir -p ${CreateDir}/.local/share/nvim/site/autoload |
| 71 |
mkdir -p ${CreateDir}/.config/nvim |
| 72 |
echo "Installing VimPlug" |
| 73 |
wget -q "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" -O ${CreateDir}/.local/share/nvim/site/autoload/plug.vim |
| 74 |
echo "Writing minimal init" |
| 75 |
printf "${INIT_TEMPLATE}" ${CreateDir} ${CreateDir} ${CreateDir} > ${CreateDir}/.config/nvim/init.vim |
| 76 |
echo "" |
| 77 |
echo "You can edit the ${CreateDirInput}/.config/nvim/init.vim to put your config" |
| 78 |
echo "You can load this config with nvim_isolated_conf.sh -l ${CreateDirInput}" |
| 79 |
echo "You can open config (init.vim) to edit with nvim_isolated_conf.sh -e ${CreateDirInput}" |
| 80 |
elif ! [ -z $EditDirInput ];then |
| 81 |
if [ -d $EditDirInput ];then |
| 82 |
if ! [ -z $EDITOR ];then |
| 83 |
$EDITOR $EditDirInput/.config/nvim/init.vim |
| 84 |
else |
| 85 |
nvim $EditDirInput/.config/nvim/init.vim |
| 86 |
fi |
| 87 |
else |
| 88 |
echo "Sorry can't load neovim config. ${LoadDir} doesn't exist" |
| 89 |
fi |
| 90 |
else |
| 91 |
printf "$USAGE" |
| 92 |
fi |