feat(make): auto install/uninstall shell completions

Add _install-completions and _uninstall-completions targets to Makefile:
- Detect shell (zsh/bash) and generate appropriate completion files
- Install to ~/.local/bin/completions/ on make install
- Remove completions on make uninstall
- Integrate with existing update/upgrade commands
This commit is contained in:
Zhengshou Lai
2026-04-13 11:07:37 +08:00
parent 929d808b3e
commit 7c39d7c9d9
+23 -4
View File
@@ -1,14 +1,16 @@
ROOT_DIR := $(shell pwd) ROOT_DIR := $(shell pwd)
VENV_MYCLAUDE := $(ROOT_DIR)/.venv/bin/myclaude VENV_MYCLAUDE := $(ROOT_DIR)/.venv/bin/myclaude
USER_LOCAL_MYCLAUDE := $(HOME)/.local/bin/myclaude USER_LOCAL_MYCLAUDE := $(HOME)/.local/bin/myclaude
COMP_DIR := $(HOME)/.local/bin/completions
SHELL_NAME := $(notdir $(SHELL))
.PHONY: help install uninstall _symlink-myclaude .PHONY: help install uninstall _symlink-myclaude _install-completions _uninstall-completions
help: help:
@echo "Usage: make [target]" @echo "Usage: make [target]"
@echo "" @echo ""
@echo " install Sync venv (uv or pip), symlink $(USER_LOCAL_MYCLAUDE) -> .venv/bin/myclaude" @echo " install Sync venv, symlink bin, install completions"
@echo " uninstall Remove $(USER_LOCAL_MYCLAUDE) if it is a symlink to this repo" @echo " uninstall Remove bin and completions"
install: install:
@cd "$(ROOT_DIR)" && \ @cd "$(ROOT_DIR)" && \
@@ -19,6 +21,7 @@ install:
.venv/bin/pip install -e .; \ .venv/bin/pip install -e .; \
fi fi
@$(MAKE) _symlink-myclaude @$(MAKE) _symlink-myclaude
@$(MAKE) _install-completions
_symlink-myclaude: _symlink-myclaude:
@test -x "$(VENV_MYCLAUDE)" || { echo "error: missing $(VENV_MYCLAUDE)"; exit 1; } @test -x "$(VENV_MYCLAUDE)" || { echo "error: missing $(VENV_MYCLAUDE)"; exit 1; }
@@ -26,5 +29,21 @@ _symlink-myclaude:
@ln -sf "$(VENV_MYCLAUDE)" "$(USER_LOCAL_MYCLAUDE)" @ln -sf "$(VENV_MYCLAUDE)" "$(USER_LOCAL_MYCLAUDE)"
@echo "Linked $(USER_LOCAL_MYCLAUDE) -> $(VENV_MYCLAUDE)" @echo "Linked $(USER_LOCAL_MYCLAUDE) -> $(VENV_MYCLAUDE)"
uninstall: _install-completions:
@mkdir -p "$(COMP_DIR)"
ifeq ($(SHELL_NAME),zsh)
@_MYCLAUDE_COMPLETE=zsh_source myclaude > "$(COMP_DIR)/_myclaude" 2>/dev/null && \
echo "Installed zsh completion: $(COMP_DIR)/_myclaude" || \
echo "Warning: failed to generate zsh completion"
else ifeq ($(SHELL_NAME),bash)
@_MYCLAUDE_COMPLETE=bash_source myclaude > "$(COMP_DIR)/myclaude.bash" 2>/dev/null && \
echo "Installed bash completion: $(COMP_DIR)/myclaude.bash" || \
echo "Warning: failed to generate bash completion"
endif
uninstall: _uninstall-completions
@ROOT_DIR="$(ROOT_DIR)" python3 "$(ROOT_DIR)/scripts/rm_user_local_myclaude.py" @ROOT_DIR="$(ROOT_DIR)" python3 "$(ROOT_DIR)/scripts/rm_user_local_myclaude.py"
_uninstall-completions:
@rm -f "$(COMP_DIR)/_myclaude" "$(COMP_DIR)/myclaude.bash"
@echo "Removed completions"