-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
106 lines (87 loc) · 2.51 KB
/
Makefile
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Dotfiles helper Makefile
# ------------------------
# '||:' is a shortcut to '|| true' to avoid the
# 'make: [target] Error 1 (ignored)' warning message.
# Switch to bash instead of sh
SHELL := /bin/bash
# Colors.
WHITE = \033[0m
RED = \033[31m
GREEN = \033[32m
YELLOW = \033[33m
BLUE = \033[34m
CYAN = \033[36m
FIND_PATTERN = . ! -path "./.git" ! -path "." -name ".*" ! -path "./.config"
USER_HOME ?= $$HOME
TAGS = TODO|FIXME|CHANGED|XXX|REVIEW|BUG|REFACTOR|IDEA|NOTE|WARNING
# Tasks
# -----
.PHONY: help
help: help-max-length ## Show this message.
@echo -e "Usage: make [task]\n" \
&& echo "Available tasks:" \
&& awk ' \
BEGIN {FS = ":.*?## "} \
/^[a-zA-Z_-]+:.*?## / \
{printf "$(CYAN)%-$(HELP_MAX_LENGTH)s$(WHITE) : %s\n", $$1, $$2} \
' $(MAKEFILE_LIST)
.PHONY: help-max-length
help-max-length: # Return the length of the longest explosed(commented with ##) rule name.
@$(eval HELP_MAX_LENGTH := $(shell \
awk ' \
BEGIN {FS = ":.*?## "} \
/^[a-zA-Z_-]+:.*?## / \
{print length($$1)} \
' $(MAKEFILE_LIST) \
| awk -v max=0 '{if($$1>max){max=$$1}}END{print max}' \
))
.PHONY: link
link: ## Create symlinks for all files in $HOME.
@for f in $$(find $(FIND_PATTERN) -exec readlink -f {} \;); do \
ln -sfT $$f $(USER_HOME)/$$(basename $$f); \
done
.PHONY: clean
clean: ## Remove all symlinks from $HOME.
@for f in $$(find $(FIND_PATTERN) -exec basename {} \;); do \
rm -rf $(USER_HOME)/$$f; \
done
.PHONY: todo-max-length
todo-max-length: # Return the length of the longest tag name.
@$(eval TODO_MAX_LENGTH := $(shell \
echo '$(TAGS)' \
| sed -e 's/|/\n/g' \
| sort -u \
| awk '{print length}' \
| sort -nr \
| head -1 \
))
.PHONY: todo
todo: todo-max-length ## Show todos.
@find $(code) \
-type f \
-not -path "./.git/*" \
-exec \
awk '/[ ]($(TAGS)):/ \
{ \
gsub("# ", "", $$0); \
gsub("// ", "", $$0); \
gsub("<!--", "", $$0); gsub("-->", "", $$0); \
gsub("\"", "", $$0); \
gsub(/\.\./, "", $$0); \
gsub(/^[ \t]+/, "", $$0); \
gsub(/:/, "", $$0); \
gsub(/\.\//, "", FILENAME); \
TYPE = $$1; $$1 = ""; \
MESSAGE = $$0; \
LINE = NR; \
printf \
"$(CYAN)%-$(TODO_MAX_LENGTH)s|$(WHITE):"\
"%s|: $(CYAN)%s$(WHITE)($(BLUE)%s$(WHITE))\n" \
, TYPE, MESSAGE, FILENAME, LINE \
}' \
{} \; | column -s '|' -t
.PHONY: config
config: ## Copy content of repo's .config directory in $HOME/.config
@for config in $$(ls "./.config"); do \
cp -r "./.config/$$config" "$(USER_HOME)/.config"; \
done