SRC_DIR    := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
TARGET_DIR := ~/.vim
PLUG_URL   := https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
PLUG_PATH  := $(SRC_DIR)/autoload/plug.vim

include ../lib/shared.mk

install: | init update

init:
ifneq ($(call cmd_exist,vim), true)
	$(error Vim not installed)
endif
	$(info => Setting up vim)
	@ $(mk_link) $(SRC_DIR) $(TARGET_DIR)
	@ $(mk_link) $(SRC_DIR)/vimrc ~/.vimrc

update:
ifneq ($(call cmd_exist,vim), true)
	$(error Vim not installed)
endif
	$(info => Updating vim)
	curl -fsLo $(PLUG_PATH) $(PLUG_URL) ; $(report) "vim plug setup"
	vim +PlugInstall +PlugUpdate +qall ; $(report) "downloading/updating plugins"

remove:
	$(info => Removing vim config)
	@ $(rm_link) ~/.vimrc
	@ $(rm_link) $(TARGET_DIR)