Files
myagents/scripts/install_completion.sh
T
Zhengshou Lai 2618f626a7 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.
2026-04-17 00:02:41 +08:00

42 lines
1.2 KiB
Bash
Executable File

#!/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