-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
76 lines (64 loc) · 2.12 KB
/
Makefile
File metadata and controls
76 lines (64 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# List of packages to manage with stow. Default: All
PACKAGES ?= $(filter-out .git .github, $(wildcard */))
# Directory where stow will look for packages. Default is current directory
DIR ?= $$(pwd)
# Default location where stow will create symbolic links
TARGET ?= ${HOME}
# Stow command to create links
STOW_CMD = stow \
--dir="${DIR}" \
--target="${TARGET}" \
--ignore="\.DS_Store" \
--ignore=".*\.template" \
--no-folding \
--verbose
# Function to backup existing files for a specific package if they exist
# egrep + sed combined is used instead of native grep -e syntax to be
# compatible with non GNU grep on MacOS.
define backup_if_exists
checks=$$(${STOW_CMD} --no --verbose ${1} 2>&1 | \
egrep '\* existing target is ' | \
sed 's/ \* existing target is neither a link nor a directory: //'); \
for file in $$checks; do \
filepath=${TARGET}/$$file; \
backup_suffix="backup-$$(date -u +%Y%m%d%H%M%S)"; \
echo "Creating backup $$filepath.$$backup_suffix"; \
mv "$$filepath" "$$filepath.$$backup_suffix"; \
done
endef
# Default rule to create symbolic links for all packages
all: stow
debug:
${STOW_CMD} --no $(PACKAGES) 2>&1
# Rule to backup existing configurations
backup:
@echo "Checking for existing files to backup..."
@$(foreach package,$(PACKAGES), \
$(call backup_if_exists,$(package));)
# Rule to link configurations using stow
stow: backup
@echo "Applying stow for packages..."
@$(foreach package,${PACKAGES}, \
$(STOW_CMD) ${package};)
# Rule to remove symbolic links
unstow:
@echo "Removing stow links for packages..."
@$(foreach package,$(PACKAGES), \
$(STOW_CMD) -D $(package);)
# Rule to reapply symbolic links
restow: backup unstow stow
# Rule to display help
help:
@echo ""
@echo "\033[1mUSAGE\033[0m"
@echo ""
@echo " make [target]"
@echo ""
@echo "\033[1mTARGETS\033[0m"
@echo ""
@echo " stow - Create symlinks for all packages (\033[32mdefault\033[0m)"
@echo " restow - Reapply symlinks for all packages"
@echo " unstow - Remove symlinks for all packages (\033[31mcaution\033[0m)"
@echo " help - Show this help message"
@echo ""
.PHONY: all backup stow unstow restow help