Skip to content

Instantly share code, notes, and snippets.

@geoffholden
Created November 7, 2016 18:17
Show Gist options
  • Save geoffholden/661804d9ff8ba08f3cf10d225e7960e2 to your computer and use it in GitHub Desktop.
Save geoffholden/661804d9ff8ba08f3cf10d225e7960e2 to your computer and use it in GitHub Desktop.
Makefile for dotfiles
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