Skip to content

Commit 76df525

Browse files
committed
refactor(setup): split Makefile into mise tasks and shell scripts
Reorganize the Makefile as a thin dispatcher to mise tasks, with the setup logic split across mise/tasks/ and scripts/. - Centralize colored output helpers in scripts/common.sh - Keep in scripts/ only what bootstrap requires before mise is available (homebrew, mise) or what is reused across multiple tasks (link-dotfiles, install-zinit, refresh-zsh-completion) - Inline single-use thin wrappers directly into mise tasks - Add a help target that lists tasks grouped by section
1 parent d37bfb0 commit 76df525

22 files changed

Lines changed: 500 additions & 184 deletions

.github/workflows/ci.yaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ defaults:
1717
run:
1818
shell: bash -euo pipefail {0}
1919

20+
permissions:
21+
contents: read
22+
2023
jobs:
21-
build:
24+
test:
2225
runs-on: ${{ matrix.os }}
2326
strategy:
2427
matrix:
@@ -28,8 +31,11 @@ jobs:
2831
steps:
2932
- name: Checkout repository
3033
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
31-
- name: Install
34+
- name: Install mise
35+
run: |
36+
curl -fsSL https://mise.run | sh
37+
echo "${HOME}/.local/bin" >> "${GITHUB_PATH}"
38+
- name: Check Makefile entrypoints
3239
run: |
33-
make init
34-
make brew
35-
make zinit
40+
make help
41+
make -n install

Makefile

Lines changed: 39 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,180 +1,50 @@
1-
XDG_CONFIG_FILES := bat cmux ghostty git mise nvim tmux
2-
EXCLUDE_FILES := .DS_Store .git .github .gitignore .gitmodules .claude .tmux
3-
CLAUDE_FILES := .claude/settings.json .claude/statusline.py
4-
DOT_FILES := $(filter-out $(EXCLUDE_FILES), $(wildcard .??*))
5-
DOT_FILES_ALL := $(DOT_FILES) $(XDG_CONFIG_FILES)
1+
.DEFAULT_GOAL := help
2+
3+
MISE_TASK := ./scripts/run-mise-task.sh
4+
5+
.PHONY: help
6+
help: ## タスク一覧を表示する
7+
@awk 'BEGIN { FS = ":.*##" } \
8+
/^## .* ##$$/ { \
9+
title = $$0; \
10+
gsub(/^## /, "", title); \
11+
gsub(/ ##$$/, "", title); \
12+
printf "\n\033[1m%s\033[0m\n", title; \
13+
next; \
14+
} \
15+
/^[a-zA-Z0-9][a-zA-Z0-9_-]+:.*##/ { \
16+
desc = $$2; \
17+
gsub(/^[ \t]+/, "", desc); \
18+
printf " \033[36m%-24s\033[0m %s\n", $$1, desc; \
19+
}' $(MAKEFILE_LIST)
20+
21+
## セットアップ ##
622

7-
XDG_CONFIG_HOME ?= $(HOME)/.config
8-
9-
BREW_CMD := $(shell command -v brew 2> /dev/null)
10-
MISE_CMD := $(shell command -v mise 2> /dev/null)
11-
ZINIT_DIR := $(HOME)/.local/share/zinit
12-
ZINIT_INSTALLED := $(shell test -d "$(ZINIT_DIR)/zinit.git" && echo installed)
13-
ZINIT_SCRIPT := $(ZINIT_DIR)/zinit.git/zinit.zsh
14-
TPM_DIR := $(XDG_CONFIG_HOME)/tmux/plugins/tpm
15-
TPM_INSTALLED := $(shell test -d "$(TPM_DIR)/.git" && echo installed)
16-
17-
ZSH_COMPLETIONS_DIR := $(XDG_CACHE_HOME)/zsh/completions
18-
ZSH_COMPDUMP := $(XDG_CACHE_HOME)/zsh/.zcompdump
19-
20-
COLOR_INFO := \033[1;34m
21-
COLOR_SUCCESS := \033[1;32m
22-
COLOR_SKIP := \033[1;33m
23-
COLOR_RESET := \033[0m
23+
.PHONY: install
24+
install: bootstrap ## すべての dotfiles セットアップタスクを実行する
25+
@$(MISE_TASK) dotfiles:install
2426

25-
.PHONY: all
26-
all: init brew zinit tpm mise prek refresh-completion treesitter fonts
27+
.PHONY: bootstrap
28+
bootstrap: brew mise ## make install に必要な最小ツールを用意する
2729

2830
.PHONY: brew
29-
brew:
30-
ifeq ($(shell uname), Darwin)
31-
ifeq ($(BREW_CMD),)
32-
@printf "$(COLOR_INFO)==> Homebrew をインストールします$(COLOR_RESET)\n"
33-
ifeq ($(shell uname -m), arm64)
34-
NONINTERACTIVE=1 arch -arm64e /bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
35-
endif
36-
NONINTERACTIVE=1 arch -x86_64 /bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
37-
@printf "$(COLOR_SUCCESS)✔ Homebrew のインストールが完了しました$(COLOR_RESET)\n"
38-
else
39-
@printf "$(COLOR_SKIP)✔ Homebrew は既にインストール済みのためスキップします$(COLOR_RESET)\n"
40-
endif
41-
else
42-
@printf "$(COLOR_SKIP)✔ macOS 以外のため Homebrew インストールをスキップします$(COLOR_RESET)\n"
43-
endif
31+
brew: ## Homebrew をインストールする
32+
@./scripts/install-homebrew.sh
4433

45-
.PHONY: clean
46-
clean:
47-
@printf "$(COLOR_INFO)==> シンボリックリンクを削除します$(COLOR_RESET)\n"
48-
@-$(foreach f, $(DOT_FILES), unlink $(HOME)/$(f);)
49-
@-$(foreach f, $(XDG_CONFIG_FILES), unlink $(XDG_CONFIG_HOME)/$(f);)
50-
@printf "$(COLOR_SUCCESS)✔ clean が完了しました$(COLOR_RESET)\n"
34+
.PHONY: mise
35+
mise: ## mise をインストールする
36+
@./scripts/install-mise.sh
5137

52-
.PHONY: install
53-
install:
54-
@printf "$(COLOR_INFO)==> すべてのセットアップタスクを実行します$(COLOR_RESET)\n"
55-
$(MAKE) all
56-
@printf "$(COLOR_SUCCESS)✔ install が完了しました$(COLOR_RESET)\n"
38+
## dotfiles ##
5739

5840
.PHONY: init
59-
init:
60-
@printf "$(COLOR_INFO)==> シンボリックリンクを初期化します$(COLOR_RESET)\n"
61-
mkdir -p $(XDG_CONFIG_HOME)
62-
@-$(foreach f, $(DOT_FILES), ln -sf "$(PWD)/$(f)" "$(HOME)";)
63-
@-$(foreach f, $(XDG_CONFIG_FILES), ln -sf "$(PWD)/$(f)" "$(XDG_CONFIG_HOME)";)
64-
mkdir -p $(HOME)/.claude
65-
@-$(foreach f, $(CLAUDE_FILES), ln -sf "$(PWD)/$(f)" "$(HOME)/$(f)";)
66-
@printf "$(COLOR_SUCCESS)✔ init が完了しました$(COLOR_RESET)\n"
41+
init: ## dotfiles のシンボリックリンクを作成する
42+
@$(MISE_TASK) dotfiles:init
6743

68-
.PHONY: list
69-
list:
70-
@printf "$(COLOR_INFO)==> 管理対象ファイルを一覧表示します$(COLOR_RESET)\n"
71-
@$(foreach f, $(DOT_FILES_ALL), ls -dF $(f);)
72-
@printf "$(COLOR_SUCCESS)✔ list が完了しました$(COLOR_RESET)\n"
44+
.PHONY: clean
45+
clean: ## dotfiles のシンボリックリンクを削除する
46+
@$(MISE_TASK) dotfiles:clean
7347

7448
.PHONY: upgrade
75-
upgrade:
76-
@printf "$(COLOR_INFO)==> 各種ツールのアップグレードを実行します$(COLOR_RESET)\n"
77-
ifeq ($(shell uname), Darwin)
78-
ifeq ($(BREW_CMD),)
79-
@printf "$(COLOR_SKIP)✔ Homebrew は未インストールのためスキップします$(COLOR_RESET)\n"
80-
else
81-
@printf "$(COLOR_INFO) -> Homebrew を更新します$(COLOR_RESET)\n"
82-
@brew update
83-
@HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade
84-
@printf "$(COLOR_SUCCESS)✔ Homebrew のアップグレードが完了しました$(COLOR_RESET)\n"
85-
endif
86-
else
87-
@printf "$(COLOR_SKIP)✔ macOS 以外のため Homebrew アップグレードをスキップします$(COLOR_RESET)\n"
88-
endif
89-
ifeq ($(ZINIT_INSTALLED),)
90-
@printf "$(COLOR_SKIP)✔ zinit は未インストールのためスキップします$(COLOR_RESET)\n"
91-
else
92-
@printf "$(COLOR_INFO) -> zinit を更新します$(COLOR_RESET)\n"
93-
@zsh -ic "source \"$(ZINIT_SCRIPT)\"; typeset -i exit_code=0; zinit self-update || exit_code=$$?; zinit update --parallel || exit_code=$$?; wait || exit_code=$$?; exit $$exit_code"
94-
@printf "$(COLOR_SUCCESS)✔ zinit のアップグレードが完了しました$(COLOR_RESET)\n"
95-
endif
96-
@printf "$(COLOR_SUCCESS)✔ upgrade が完了しました$(COLOR_RESET)\n"
97-
98-
.PHONY: mise
99-
mise:
100-
ifeq ($(MISE_CMD),)
101-
@printf "$(COLOR_INFO)==> mise をインストールします$(COLOR_RESET)\n"
102-
ifeq ($(shell uname), Darwin)
103-
HOMEBREW_NO_AUTO_UPDATE=1 brew install mise
104-
else
105-
curl -s https://mise.run | sh
106-
endif
107-
@printf "$(COLOR_SUCCESS)✔ mise のインストールが完了しました$(COLOR_RESET)\n"
108-
else
109-
@printf "$(COLOR_SKIP)✔ mise は既にインストール済みのためスキップします$(COLOR_RESET)\n"
110-
endif
111-
mise install
112-
113-
.PHONY: prek
114-
prek:
115-
@printf "$(COLOR_INFO)==> prek フックをインストールします$(COLOR_RESET)\n"
116-
@prek install --overwrite --install-hooks
117-
@printf "$(COLOR_SUCCESS)✔ prek フックのインストールが完了しました$(COLOR_RESET)\n"
118-
119-
.PHONY: completions
120-
completions:
121-
@printf "$(COLOR_INFO)==> zsh 補完スクリプトを再生成します$(COLOR_RESET)\n"
122-
@rm -rf "$(ZSH_COMPLETIONS_DIR)"
123-
@mkdir -p "$(ZSH_COMPLETIONS_DIR)"
124-
@zsh -ic '\
125-
setopt clobber; \
126-
ZSH_LOCAL_COMPLETIONS="$(ZSH_COMPLETIONS_DIR)"; \
127-
[[ -x "$$(command -v docker)" ]] && docker completion zsh >! "$$ZSH_LOCAL_COMPLETIONS/_docker"; \
128-
[[ -x "$$(command -v kubectl)" ]] && kubectl completion zsh >! "$$ZSH_LOCAL_COMPLETIONS/_kubectl"; \
129-
[[ -n "$$(command -v mise)" ]] && mise completion zsh >! "$$ZSH_LOCAL_COMPLETIONS/_mise"; \
130-
[[ -x "$$(command -v uv)" ]] && uv generate-shell-completion zsh >! "$$ZSH_LOCAL_COMPLETIONS/_uv"; \
131-
'
132-
@printf "$(COLOR_SUCCESS)✔ completions の再生成が完了しました$(COLOR_RESET)\n"
133-
134-
.PHONY: compdump
135-
compdump:
136-
@printf "$(COLOR_INFO)==> zsh 補完ダンプを更新します$(COLOR_RESET)\n"
137-
@rm -f "$(ZSH_COMPDUMP)" "$(ZSH_COMPDUMP).zwc"
138-
@zsh -ic 'autoload -Uz compinit; compinit -u -C -d "$(ZSH_COMPDUMP)"; [ -f "$(ZSH_COMPDUMP)" ] && zcompile "$(ZSH_COMPDUMP)"'
139-
@printf "$(COLOR_SUCCESS)✔ compdump の更新が完了しました$(COLOR_RESET)\n"
140-
141-
.PHONY: refresh-completion
142-
refresh-completion: completions compdump
143-
@printf "$(COLOR_SUCCESS)✔ zsh 補完の再生成とダンプ更新が完了しました$(COLOR_RESET)\n"
144-
145-
.PHONY: zinit
146-
zinit:
147-
ifeq ($(ZINIT_INSTALLED),)
148-
@printf "$(COLOR_INFO)==> zinit をインストールします$(COLOR_RESET)\n"
149-
NO_INPUT=1 NO_ANNEXES=1 NO_EDIT=1 NO_TUTORIAL=1 bash -c "$$(curl --fail --show-error --silent --location https://raw.githubusercontent.com/zdharma-continuum/zinit/HEAD/scripts/install.sh)"
150-
@printf "$(COLOR_SUCCESS)✔ zinit のインストールが完了しました$(COLOR_RESET)\n"
151-
else
152-
@printf "$(COLOR_SKIP)✔ zinit は既にインストール済みのためスキップします$(COLOR_RESET)\n"
153-
endif
154-
155-
.PHONY: tpm
156-
tpm: init
157-
ifeq ($(TPM_INSTALLED),)
158-
@printf "$(COLOR_INFO)==> TPM をインストールします$(COLOR_RESET)\n"
159-
@mkdir -p "$(XDG_CONFIG_HOME)/tmux/plugins"
160-
git clone https://github.com/tmux-plugins/tpm "$(TPM_DIR)"
161-
@printf "$(COLOR_SUCCESS)✔ TPM のインストールが完了しました$(COLOR_RESET)\n"
162-
else
163-
@printf "$(COLOR_SKIP)✔ TPM は既にインストール済みのためスキップします$(COLOR_RESET)\n"
164-
endif
165-
166-
.PHONY: treesitter
167-
treesitter:
168-
@printf "$(COLOR_INFO)==> Tree-sitter parser をローカル生成します$(COLOR_RESET)\n"
169-
@./nvim/scripts/build-treesitter-parsers.sh
170-
@printf "$(COLOR_SUCCESS)✔ Tree-sitter parser の生成が完了しました$(COLOR_RESET)\n"
171-
172-
.PHONY: fonts
173-
fonts:
174-
ifeq ($(shell uname), Darwin)
175-
@printf "$(COLOR_INFO)==> Moralerspace Neon フォントをインストールします$(COLOR_RESET)\n"
176-
@./scripts/install-fonts.sh
177-
@printf "$(COLOR_SUCCESS)✔ フォントのインストールが完了しました$(COLOR_RESET)\n"
178-
else
179-
@printf "$(COLOR_SKIP)✔ macOS 以外のためフォントインストールをスキップします$(COLOR_RESET)\n"
180-
endif
49+
upgrade: ## 管理対象ツールを更新する
50+
@$(MISE_TASK) dotfiles:upgrade

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ git clone https://github.com/mhiro2/dotfiles
1111
cd dotfiles
1212
make install
1313
```
14+
15+
`make install` bootstraps Homebrew/mise when needed, then delegates to mise tasks.

mise/tasks/bootstrap/homebrew

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
#MISE description="Homebrew をインストールする"
3+
set -euo pipefail
4+
5+
TASK_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
6+
readonly TASK_DIR
7+
REPO_ROOT="$(git -C "${TASK_DIR}" rev-parse --show-toplevel)"
8+
readonly REPO_ROOT
9+
cd "${REPO_ROOT}"
10+
11+
./scripts/install-homebrew.sh

mise/tasks/bootstrap/mise

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
#MISE description="mise をインストールする"
3+
set -euo pipefail
4+
5+
TASK_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
6+
readonly TASK_DIR
7+
REPO_ROOT="$(git -C "${TASK_DIR}" rev-parse --show-toplevel)"
8+
readonly REPO_ROOT
9+
cd "${REPO_ROOT}"
10+
11+
./scripts/install-mise.sh

mise/tasks/bootstrap/tpm

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
#MISE description="tmux plugin manager をインストールする"
3+
set -euo pipefail
4+
5+
TASK_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
6+
readonly TASK_DIR
7+
REPO_ROOT="$(git -C "${TASK_DIR}" rev-parse --show-toplevel)"
8+
readonly REPO_ROOT
9+
cd "${REPO_ROOT}"
10+
11+
# shellcheck source=scripts/common.sh
12+
source "${REPO_ROOT}/scripts/common.sh"
13+
14+
readonly xdg_config_home="${XDG_CONFIG_HOME:-${HOME}/.config}"
15+
readonly tpm_dir="${xdg_config_home}/tmux/plugins/tpm"
16+
17+
if [[ -d "${tpm_dir}/.git" ]]; then
18+
skip "TPM は既にインストール済みのためスキップします"
19+
exit 0
20+
fi
21+
22+
info "TPM をインストールします"
23+
mkdir -p "${xdg_config_home}/tmux/plugins"
24+
git clone https://github.com/tmux-plugins/tpm "${tpm_dir}"
25+
success "TPM のインストールが完了しました"

mise/tasks/dotfiles/clean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
#MISE description="dotfiles のシンボリックリンクを削除する"
3+
set -euo pipefail
4+
5+
TASK_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
6+
readonly TASK_DIR
7+
REPO_ROOT="$(git -C "${TASK_DIR}" rev-parse --show-toplevel)"
8+
readonly REPO_ROOT
9+
cd "${REPO_ROOT}"
10+
11+
./scripts/link-dotfiles.sh clean

mise/tasks/dotfiles/init

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
#MISE description="dotfiles のシンボリックリンクを作成する"
3+
set -euo pipefail
4+
5+
TASK_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
6+
readonly TASK_DIR
7+
REPO_ROOT="$(git -C "${TASK_DIR}" rev-parse --show-toplevel)"
8+
readonly REPO_ROOT
9+
cd "${REPO_ROOT}"
10+
11+
./scripts/link-dotfiles.sh init

mise/tasks/dotfiles/install

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
#MISE description="すべての dotfiles セットアップタスクを実行する"
3+
set -euo pipefail
4+
5+
TASK_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
6+
readonly TASK_DIR
7+
REPO_ROOT="$(git -C "${TASK_DIR}" rev-parse --show-toplevel)"
8+
readonly REPO_ROOT
9+
cd "${REPO_ROOT}"
10+
11+
mise run dotfiles:init
12+
mise run bootstrap:homebrew
13+
mise run bootstrap:tpm
14+
mise run zsh:zinit
15+
16+
mise install
17+
18+
mise run zsh:refresh-completion
19+
mise run nvim:treesitter
20+
mise run fonts:install
21+
22+
prek install --overwrite --install-hooks

mise/tasks/dotfiles/upgrade

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
#MISE description="mise tools と zinit を更新する"
3+
set -euo pipefail
4+
5+
TASK_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
6+
readonly TASK_DIR
7+
REPO_ROOT="$(git -C "${TASK_DIR}" rev-parse --show-toplevel)"
8+
readonly REPO_ROOT
9+
cd "${REPO_ROOT}"
10+
11+
# shellcheck source=scripts/common.sh
12+
source "${REPO_ROOT}/scripts/common.sh"
13+
14+
info "各種ツールのアップグレードを実行します"
15+
16+
mise self-update
17+
mise up
18+
19+
"${REPO_ROOT}/scripts/install-zinit.sh" update
20+
success "upgrade が完了しました"

0 commit comments

Comments
 (0)