Created
November 7, 2016 18:17
-
-
Save geoffholden/661804d9ff8ba08f3cf10d225e7960e2 to your computer and use it in GitHub Desktop.
Makefile for dotfiles
This file contains 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
HOSTNAME = $(shell hostname -s) | |
PWD = $(shell pwd) | |
LN = ln | |
LN_FLAGS = -sf | |
INPUT = $(shell find $(PWD) -path $(PWD)/.git -prune -o -name "*.symlink" -print | grep -v host-specific) | |
INPUT += $(shell find $(PWD) -name "*.symlink" -print | grep host-specific/$(HOSTNAME)) | |
OUTPUT = $(addprefix ~/.,$(basename $(notdir $(INPUT)))) | |
help: | |
@echo "This script is used to install and remove dotfile." | |
@echo "The available targets are:" | |
@echo " help - Display this help information" | |
@echo " install - Link your dotfiles" | |
@echo " uninstall - Unlink your dotfiles" | |
install: $(OUTPUT) | |
uninstall: | |
@rm $(OUTPUT) | |
@for target in $(OUTPUT); do \ | |
if [ -e $$target.backup ]; then \ | |
mv $$target.backup $$target; \ | |
fi; \ | |
done | |
~/.%: .git/FETCH_HEAD | |
@if [ -e $@ ]; then \ | |
dest=`readlink $@`; \ | |
if [ "$$dest" != "$(filter %/$*.symlink, $(INPUT))" ]; then \ | |
mv $@ $@.backup; \ | |
fi; \ | |
fi | |
@$(LN) $(LN_FLAGS) $(filter %/$*.symlink, $(INPUT)) $@ | |
.PHONY: install uninstall help |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment