-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
80 lines (71 loc) · 2.57 KB
/
Copy pathMakefile
File metadata and controls
80 lines (71 loc) · 2.57 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
77
78
79
80
SHELL := /usr/bin/env bash
TOOLS_DIR := $(HOME)/.local/bin
CONFIG_DIR := $(HOME)/.config/crl_ws_manager
BASHRC := $(HOME)/.bashrc
ZSHRC := $(HOME)/.zshrc
COMMANDS := ws ws-build ws-clean ws-cd-resolve ws-list ws-open ws-config ws-which
SOURCE_BEGIN := \# >>> ws manager source >>>
SOURCE_END := \# <<< ws manager source <<<
.PHONY: install uninstall purge test ci-local
install:
@bash install.sh
uninstall:
@echo "Removing symlinks from $(TOOLS_DIR) ..."
@for cmd in $(COMMANDS); do \
dest="$(TOOLS_DIR)/$$cmd"; \
if [[ -L "$$dest" ]]; then \
unlink "$$dest" && echo " Removed $$dest"; \
elif [[ -f "$$dest" ]]; then \
echo " [SKIP] $$dest is a regular file — remove manually"; \
fi; \
done
@echo "Removing shell functions file ..."
@dest="$(CONFIG_DIR)/ws_manager.bash"; \
if [[ -L "$$dest" ]]; then \
unlink "$$dest" && echo " Removed $$dest"; \
elif [[ -f "$$dest" ]]; then \
echo " [SKIP] $$dest is a regular file — remove manually"; \
fi
@dest="$(CONFIG_DIR)/ws_lib.sh"; \
if [[ -L "$$dest" ]]; then \
unlink "$$dest" && echo " Removed $$dest"; \
fi
@for rc in "$(BASHRC)" "$(ZSHRC)"; do \
if [[ -f "$$rc" ]]; then \
echo "Removing source block from $$rc ..."; \
if grep -qF '$(SOURCE_BEGIN)' "$$rc" 2>/dev/null; then \
tmp=$$(mktemp); \
awk \
-v begin='# >>> ws manager source >>>' \
-v end='# <<< ws manager source <<<' \
'BEGIN{skip=0} $$0==begin{skip=1;next} $$0==end{skip=0;next} skip==0{print}' \
"$$rc" > "$$tmp" && mv "$$tmp" "$$rc" && \
echo " Removed source block from $$rc"; \
else \
echo " Source block not found in $$rc, nothing to remove"; \
fi; \
fi; \
done
@echo "Done. Run 'source $(BASHRC)' or open a new terminal to apply."
# purge: uninstall + remove the local config file and config directory.
# The config file (~/.config/crl_ws_manager/ws_config.bash) contains user
# customisations; this target will prompt before deleting it.
purge: uninstall
@cfg="$(CONFIG_DIR)/ws_config.bash"; \
if [[ -f "$$cfg" ]]; then \
read -r -p " Delete local config $$cfg? [y/N] " ans; \
if [[ "$$ans" =~ ^[Yy]$$ ]]; then \
rm -f "$$cfg" && echo " Removed $$cfg"; \
else \
echo " Kept $$cfg"; \
fi; \
fi
@if [[ -d "$(CONFIG_DIR)" ]] && [[ -z "$$(ls -A "$(CONFIG_DIR)" 2>/dev/null)" ]]; then \
rmdir "$(CONFIG_DIR)" && echo " Removed empty directory $(CONFIG_DIR)"; \
fi
# Run bats test suite only.
test:
@bats tests/bats/*.bats
# Run a local equivalent of the CI validate job.
ci-local:
@./scripts/run_ci_local.sh