<commit_before>.PHONY: install
.DEFAULT_GOAL := help

SHELL := /bin/bash

# List up dotfiles
DOTFILES_EXCLUDES   := README.md LICENSE Makefile config install $(wildcard .??*)
DOTFILES_TARGET     := $(shell ls)
DOTFILES_FILES      := $(filter-out $(DOTFILES_EXCLUDES), $(DOTFILES_TARGET))
DOTFILES_XDG_CONFIG := $(shell ls config)

# Define path
DOTPATH    := $(HOME)/.dotfiles
VIMPATH    := $(HOME)/src/vim
NEOVIMPATH := $(HOME)/src/neovim
BASHMARKS  := $(HOME)/src/bashmarks

# Proxy settings
PROXY_TEMPLATE     := $(DOTPATH)/config/profile.d/proxy.sh.template
PROXY_SETTING      := $(DOTPATH)/config/profile.d/proxy.sh
GIT_PROXY_TEMPLATE := $(DOTPATH)/config/git/config.proxy.template
GIT_PROXY_SETTING  := $(DOTPATH)/config/git/config.proxy

define repo
	if [[ -d "$1" ]]; then \
		cd $1 && git pull && git submodule update --init --recursive; \
	else \
		git clone --depth 1 --recursive https://github.com/$2 "$1"; \
	fi
endef

list: ## Show file/directory list for deployment
	@$(foreach val, $(DOTFILES_FILES), ls -dF $(val);)
	@$(foreach val, $(DOTFILES_XDG_CONFIG), ls -dF config/$(val);)

install: proxy update deploy ## Do proxy, update and deploy

proxy: ## Set proxy
ifdef http_proxy
	sed -e 's|write_proxy_here|$(http_proxy)|g' $(PROXY_TEMPLATE) > $(PROXY_SETTING)
	sed -e 's|write_proxy_here|$(http_proxy)|g' $(GIT_PROXY_TEMPLATE) > $(GIT_PROXY_SETTING)

	source $(PROXY_SETTING)
endif

update: update-dot update-plugin ## Update dotfiles

update-dot: ## update dotfiles repository
	git fetch
	git pull

update-plugin: ## update neovim plugins
	nvim --headless -c "quitall"
	# nvim --headless -c "autocmd User PackerComplete quitall" -c "PackerSync"

deploy: ## Create symlink
	@mkdir -p $(HOME)/{.config,ghe,github}
	@$(foreach val, $(DOTFILES_FILES), ln -sfnv $(abspath $(val)) $(HOME)/.$(val);)
	@$(foreach val, $(DOTFILES_XDG_CONFIG), ln -sfnv $(abspath config/$(val)) $(HOME)/.config/$(val);)

neovim: update-neovim build-neovim ## Get edge neovim

update-neovim: ## Update neovim repository
	$(call repo,$(NEOVIMPATH),neovim/neovim)

build-neovim: ## Build neovim
	cd $(NEOVIMPATH) && \
	rm -fr .deps build/ && \
	make distclean && \<commit_msg>feat: update make update command.<commit_after>.PHONY: install
.DEFAULT_GOAL := help

SHELL := /bin/bash

# List up dotfiles
DOTFILES_EXCLUDES   := README.md LICENSE Makefile config install $(wildcard .??*)
DOTFILES_TARGET     := $(shell ls)
DOTFILES_FILES      := $(filter-out $(DOTFILES_EXCLUDES), $(DOTFILES_TARGET))
DOTFILES_XDG_CONFIG := $(shell ls config)

# Define path
DOTPATH    := $(HOME)/.dotfiles
VIMPATH    := $(HOME)/src/vim
NEOVIMPATH := $(HOME)/src/neovim
BASHMARKS  := $(HOME)/src/bashmarks

# Proxy settings
PROXY_TEMPLATE     := $(DOTPATH)/config/profile.d/proxy.sh.template
PROXY_SETTING      := $(DOTPATH)/config/profile.d/proxy.sh
GIT_PROXY_TEMPLATE := $(DOTPATH)/config/git/config.proxy.template
GIT_PROXY_SETTING  := $(DOTPATH)/config/git/config.proxy

define repo
	if [[ -d "$1" ]]; then \
		cd $1 && git pull && git submodule update --init --recursive; \
	else \
		git clone --depth 1 --recursive https://github.com/$2 "$1"; \
	fi
endef

list: ## Show file/directory list for deployment
	@$(foreach val, $(DOTFILES_FILES), ls -dF $(val);)
	@$(foreach val, $(DOTFILES_XDG_CONFIG), ls -dF config/$(val);)

install: proxy update deploy ## Do proxy, update and deploy

proxy: ## Set proxy
ifdef http_proxy
	sed -e 's|write_proxy_here|$(http_proxy)|g' $(PROXY_TEMPLATE) > $(PROXY_SETTING)
	sed -e 's|write_proxy_here|$(http_proxy)|g' $(GIT_PROXY_TEMPLATE) > $(GIT_PROXY_SETTING)

	source $(PROXY_SETTING)
endif

update: update-dot update-plugin ## Update dotfiles

update-dot: ## update dotfiles repository
	git fetch
	git pull

update-plugin: ## update neovim plugins
	nvim --headless -c "quitall"
	nvim --headless -c "autocmd User PackerComplete quitall" -c "PackerSync"

deploy: ## Create symlink
	@mkdir -p $(HOME)/{.config,ghe,github}
	@$(foreach val, $(DOTFILES_FILES), ln -sfnv $(abspath $(val)) $(HOME)/.$(val);)
	@$(foreach val, $(DOTFILES_XDG_CONFIG), ln -sfnv $(abspath config/$(val)) $(HOME)/.config/$(val);)

neovim: update-neovim build-neovim ## Get edge neovim

update-neovim: ## Update neovim repository
	$(call repo,$(NEOVIMPATH),neovim/neovim)

build-neovim: ## Build neovim
	cd $(NEOVIMPATH) && \
	rm -fr .deps build/ && \
	make distclean && \
{'fraction_non_alphanumeric': 0.16490340386384544, 'fraction_numerical': 0.0022999080036798527, 'mean_word_length': 4.484237074401009, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '149636', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1639, 'n_words': 388}