-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
149 lines (120 loc) · 4.68 KB
/
Copy pathMakefile
File metadata and controls
149 lines (120 loc) · 4.68 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
.DEFAULT_GOAL := install
# Detect operating system
OS := $(shell uname | tr "[:upper:]" "[:lower:]")
# List of packages to manage with stow. Default: All packages in stow_packager directory
ifeq ($(OS),linux)
PACKAGES := fonts nvim terminator tmux zsh wezterm mise ghostty zed
else ifeq ($(OS),darwin)
PACKAGES := nvim tmux zsh wezterm mise ghostty zed
else
@echo "No stow packages defined for OS: $(OS)"
endif
# List of krew plugins to be installed.
KREW_PLUGINS := krew profefe neat edit-status rabbitmq
# Directory where stow will look for packages
STOW_SRC_DIR ?= $$(pwd)/stow_packages
# Default location where stow will create symbolic links
STOW_TARGET_DIR ?= ${HOME}
# Stow command to create links. Packages use real dotfile names.
STOW_CMD = stow \
--dir="${STOW_SRC_DIR}" \
--target="${STOW_TARGET_DIR}" \
--no-folding \
--verbose
# Function to backup existing files for a specific package if they exist.
# grep + awk keeps the conflict parsing portable across GNU and BSD userlands.
define backup_if_exists
echo "Backing up existing files for package: ${1}"; \
checks=$$(${STOW_CMD} --no ${1} 2>&1 | \
grep 'existing target' | \
awk -F': ' '{print $$NF}'); \
for file in $$checks; do \
echo "Found existing file to backup: $$file"; \
filepath=${STOW_TARGET_DIR}/$$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
##@ Dotfiles install
.PHONY: install
install: tools stow mise-install krew-plugins-install ## Install required system tools, configure dotfiles and create symlinks (default)
.PHONY: update
update: tools restow zinit-update krew-plugins-update ## Update dotfiles
mise-install:
mise install
# Install the required tools and apps
.PHONY: tools
ifeq ($(OS),linux)
tools:
@echo "Adding Wezterm apt repository..."
curl -fsSL https://apt.fury.io/wez/gpg.key | sudo gpg --yes --dearmor -o /usr/share/keyrings/wezterm-fury.gpg
echo 'deb [signed-by=/usr/share/keyrings/wezterm-fury.gpg] https://apt.fury.io/wez/ * *' | sudo tee /etc/apt/sources.list.d/wezterm.list
sudo chmod 644 /usr/share/keyrings/wezterm-fury.gpg
@echo "Installing apt packages..."
sudo apt update
sudo apt -y install cmake make zsh neovim tmux python3-pip autojump fortune curl python3-pynvim stow wezterm
@echo "Installing Zed..."
curl -f https://zed.dev/install.sh | sh
else ifeq ($(OS),darwin)
brew install stow mise oh-my-posh starship
else
tools:
@echo "No tools installation defined for OS: $(OS)"
endif
##@ Symlinks management
.PHONY: debug
debug: ## Show stow detailed operations
${STOW_CMD} --no $(PACKAGES) 2>&1
# Backup existing files before create symlinks
.PHONY: backup
backup:
@echo "Checking for existing files to backup..."
@$(foreach package,$(PACKAGES), \
$(call backup_if_exists,$(package));)
.PHONY: stow
stow: backup ## Create symlinks
@echo "Applying stow for packages..."
@$(foreach package,${PACKAGES}, \
$(STOW_CMD) ${package};)
.PHONY: unstow
unstow: ## Remove symlincs
@echo "Removing stow links for packages..."
@$(foreach package,$(PACKAGES), \
$(STOW_CMD) -D $(package);)
.PHONY: restow
restow: backup unstow stow ## Reapply symlinks
##@ Zinit management
.PHONY: zinit-update
zinit-update: ## Update zinit and zinit plugins
zsh -c 'source $${HOME}/.zshrc; zinit-update'
.PHONY: help
help:
@echo ""
@echo "\033[1mUsage\033[0m"
@echo " make \033[36m<target>\033[0m"
@echo " make \033[36mhelp\033[0m Shows this help"
@awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@echo ""
##@ MacOS specific tools installation
.PHONY: brew-tools
ifeq ($(OS),darwin)
brew-tools: ## Install Homebrew formulae and casks defined in Brewfile (MacOS only)
brew bundle --file=./Brewfile
endif
ifeq ($(OS),darwin)
brew-update-dump: ## Dump Homebrew formulae and casks to Brewfile (MacOS only)
brew bundle dump --file=./Brewfile --no-vscode --no-go --no-krew --force
endif
##@ Krew management
krew-plugins-install: ## Install krew plugins defined in KREW_PLUGINS variable
krew install $(KREW_PLUGINS)
krew-plugins-update: ## Update krew plugins defined in KREW_PLUGINS variable
krew upgrade
##@ Zed configuration
zed-installed-plugins-list: ## Get the list of the installed plugins in the right format to include to the configuration to auto-installed
ifeq ($(OS),linux)
echo "{" && ls ~/.local/share/zed/extensions/installed/ | sed 's/.*/ "&": true,/' | sed '$$ s/,$$//' && echo "}"
else ifeq ($(OS),darwin)
@echo "{" && ls ~/Library/"Application Support"/Zed/extensions/installed/ | sed 's/.*/ "&": true,/' | sed '$$ s/,$$//' && echo "}"
endif