feat(make): extract completion install to standalone script

Move shell-specific completion generation from Makefile inline
logic to scripts/install_completion.sh for easier maintenance.
This commit is contained in:
Zhengshou Lai
2026-04-17 00:02:41 +08:00
parent c890ef6d72
commit 2618f626a7
2 changed files with 42 additions and 11 deletions
+1 -11
View File
@@ -2,7 +2,6 @@ ROOT_DIR := $(shell pwd)
VENV_MYCLAUDE := $(ROOT_DIR)/.venv/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 _install-completions _uninstall-completions
@@ -30,16 +29,7 @@ _symlink-myclaude:
@echo "Linked $(USER_LOCAL_MYCLAUDE) -> $(VENV_MYCLAUDE)"
_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
@$(ROOT_DIR)/scripts/install_completion.sh "$(VENV_MYCLAUDE)" "$(COMP_DIR)"
uninstall: _uninstall-completions
@ROOT_DIR="$(ROOT_DIR)" python3 "$(ROOT_DIR)/scripts/rm_user_local_myclaude.py"
+41
View File
@@ -0,0 +1,41 @@
#!/bin/bash
# Install shell completions for myclaude to user directory only
# Usage: install_completion.sh <venv_myclaude_path> <comp_dir>
VENV_MYCLAUDE="$1"
COMP_DIR="$2"
if [[ -z "$VENV_MYCLAUDE" || -z "$COMP_DIR" ]]; then
echo "Usage: $0 <venv_myclaude_path> <comp_dir>" >&2
exit 1
fi
USER_SHELL=$(basename "$SHELL")
install_zsh_completion() {
mkdir -p "$COMP_DIR" 2>/dev/null || { echo "Error: cannot create $COMP_DIR" >&2; return 1; }
if _MYCLAUDE_COMPLETE=zsh_source "$VENV_MYCLAUDE" > "$COMP_DIR/_myclaude" 2>/dev/null; then
echo "Installed zsh completion: $COMP_DIR/_myclaude"
return 0
else
echo "Warning: failed to generate zsh completion" >&2
return 1
fi
}
install_bash_completion() {
mkdir -p "$COMP_DIR" 2>/dev/null || { echo "Error: cannot create $COMP_DIR" >&2; return 1; }
if _MYCLAUDE_COMPLETE=bash_source "$VENV_MYCLAUDE" > "$COMP_DIR/myclaude.bash" 2>/dev/null; then
echo "Installed bash completion: $COMP_DIR/myclaude.bash"
return 0
else
echo "Warning: failed to generate bash completion" >&2
return 1
fi
}
if [[ "$USER_SHELL" == "zsh" ]]; then
install_zsh_completion
elif [[ "$USER_SHELL" == "bash" ]]; then
install_bash_completion
fi