nvim.d/helpers/config

55 lines
1.5 KiB
Text
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$( cd "$( dirname $0 )/.." && pwd )"
NEOVIM_CONFIG_SOURCE_DIR="${ROOT_DIR}/neovim"
NEOVIM_CONFIG_DESTINATION_DIR="${XDG_CONFIG_HOME}/nvim"
action="$1"
function backup {
if [ -d "${NEOVIM_CONFIG_DESTINATION_DIR}" ]; then
echo "INFO: backing up existing config..."
timestamp=$( date +"%Y.%m.%dT%H.%M.%S" )
backup_dir="${ROOT_DIR}/backup"
mkdir -p ${backup_dir}
cd ${NEOVIM_CONFIG_DESTINATION_DIR}
tar czf "${backup_dir}/neovim-config-${timestamp}.tar.gz" .
fi
}
function clean {
rm -f ${NEOVIM_CONFIG_DESTINATION_DIR}/init.lua
find ${NEOVIM_CONFIG_DESTINATION_DIR} -maxdepth 1 -mindepth 1 -type d -not -iwholename "*/plugin" | xargs rm -rf
}
function update {
mkdir -p ${NEOVIM_CONFIG_DESTINATION_DIR}
# Syncing the neovim configuration files
echo "INFO: syncing ${NEOVIM_CONFIG_SOURCE_DIR} to ${NEOVIM_CONFIG_DESTINATION_DIR}..."
rsync -avh ${NEOVIM_CONFIG_SOURCE_DIR}/ ${NEOVIM_CONFIG_DESTINATION_DIR}
chmod a-rwx,u+rwx ${NEOVIM_CONFIG_DESTINATION_DIR}
# Ensuring the data directories are present
mkdir -p ${XDG_DATA_HOME}/nvim/{backup,swap,undo,view,spell}
chmod 0700 ${XDG_DATA_HOME}/nvim/{backup,swap,undo,view,spell}
}
case ${action} in
backup)
backup
;;
clean)
clean
;;
update)
update
;;
*)
echo "ERROR: Unknown action ${action}"
exit 1
;;
esac