Enhanced Make completion with parameters and conditions for Bash and Zsh.
make-completion-enhanced adds intelligent autocompletion to your Makefiles by parsing special comment annotations. It supports typed parameters, conditional suggestions, per-target parameters, and works with both Bash and Zsh shells.
- Typed Parameters: Support for
enum,bool, and custom types - Global & Per-Target Parameters: Define parameters globally or for specific targets
- Conditional Suggestions: Dynamic parameter suggestions based on context
- Multi-Shell Support: Works with both Bash and Zsh
- Smart Caching: Automatically caches and updates completions
- DEB Packaging: Easy installation via
.debpackage
# Clone the repository
git clone https://github.com/yourusername/make-completion-enhanced.git
cd make-completion-enhanced
# For Bash
echo "source $(pwd)/make-completion-enhanced.bash" >> ~/.bashrc
source ~/.bashrc
# For Zsh
echo "source $(pwd)/_make-completion-enhanced" >> ~/.zshrc
source ~/.zshrc# Build the package
make deb
# Install
sudo dpkg -i ../make-completion-enhanced_*.deb# Install system-wide
sudo make install
# Restart your shell or source the completion script
source /etc/bash_completion.d/make-completion-enhanced # Bash
source /usr/share/zsh/site-functions/_make-completion-enhanced # ZshAdd special comments to your Makefile to define parameters:
## PARAM <name>: <value1> <value2> ...
## PARAM <name> TYPE=<type> [REQUIRED] [DEFAULT=<value>]
## TARGET <target-name>## PARAM env: dev stage prod
## PARAM env TYPE=enum REQUIRED
## PARAM debug: True False
## PARAM debug TYPE=bool DEFAULT=False
## PARAM verbose: True False
## PARAM verbose TYPE=bool DEFAULT=False
## TARGET run
## PARAM app: api worker scheduler
## PARAM app TYPE=enum REQUIRED
## TARGET deploy
## PARAM region: us-east-1 us-west-2 eu-west-1
## PARAM region TYPE=enum DEFAULT=us-east-1
run:
@echo "Running app=$(app) env=$(env) debug=$(debug)"
deploy:
@echo "Deploying to $(region) env=$(env)"
build:
@echo "Building for env=$(env)"
test:
@echo "Testing with verbose=$(verbose)"# Tab completion for targets
make <TAB>
# Shows: run deploy build test
# Global parameters available for all targets
make build env=<TAB>
# Shows: dev stage prod
make build debug=<TAB>
# Shows: True False
# Target-specific parameters
make run <TAB>
# Shows: env=dev env=stage env=prod app=api app=worker app=scheduler debug=True debug=False
make run app=<TAB>
# Shows: api worker scheduler
make deploy region=<TAB>
# Shows: us-east-1 us-west-2 eu-west-1
# Combined usage
make run app=api env=dev debug=True
make deploy region=us-west-2 env=prodGlobal parameters are available for all targets:
## PARAM <name>: <value1> <value2> <value3>Example:
## PARAM env: dev stage prodDefine parameters specific to a target:
## TARGET <target-name>
## PARAM <name>: <value1> <value2>Example:
## TARGET deploy
## PARAM region: us-east-1 us-west-2## PARAM env: dev stage prod
## PARAM env TYPE=enum REQUIRED## PARAM debug: True False
## PARAM debug TYPE=bool DEFAULT=False- REQUIRED: Parameter must be provided
- DEFAULT=: Default value if not specified
- TYPE=: Parameter type (enum, bool, etc.)
## PARAM env TYPE=enum REQUIRED
## PARAM debug TYPE=bool DEFAULT=False
## PARAM level TYPE=enum DEFAULT=info## PARAM env: development staging production
## PARAM env TYPE=enum REQUIRED
## TARGET deploy-api
## PARAM replicas: 1 2 3 5
## PARAM replicas TYPE=enum DEFAULT=2
## TARGET deploy-worker
## PARAM queue: high normal low
## PARAM queue TYPE=enum REQUIRED
deploy-api:
@echo "Deploying API with $(replicas) replicas to $(env)"
kubectl apply -f api-deployment.yaml
deploy-worker:
@echo "Deploying worker for $(queue) queue to $(env)"
kubectl apply -f worker-deployment.yamlUsage:
make deploy-api env=production replicas=5
make deploy-worker env=staging queue=high## PARAM ci: True False
## PARAM ci TYPE=bool DEFAULT=False
## TARGET test
## PARAM coverage: True False
## PARAM coverage TYPE=bool DEFAULT=True
## TARGET build
## PARAM optimize: True False
## PARAM optimize TYPE=bool DEFAULT=True
test:
@if [ "$(coverage)" = "True" ]; then \
npm test -- --coverage; \
else \
npm test; \
fi
build:
@if [ "$(optimize)" = "True" ]; then \
npm run build -- --optimization; \
else \
npm run build; \
fi
ci: test build
@echo "CI pipeline complete"Usage:
make test coverage=True
make build optimize=False
make ci ci=True## PARAM env: local docker kubernetes
## PARAM env TYPE=enum DEFAULT=local
## TARGET up
## PARAM detach: True False
## PARAM detach TYPE=bool DEFAULT=False
## TARGET logs
## PARAM follow: True False
## PARAM follow TYPE=bool DEFAULT=True
up:
@if [ "$(detach)" = "True" ]; then \
docker-compose up -d; \
else \
docker-compose up; \
fi
logs:
@if [ "$(follow)" = "True" ]; then \
docker-compose logs -f; \
else \
docker-compose logs; \
fi
down:
docker-compose downUsage:
make up detach=True
make logs follow=False
make down- Parsing: The completion script uses
awkto parse Makefile comments - Caching: Results are cached in
~/.cache/make-completion-enhanced.cache - Auto-Update: Cache is regenerated when Makefile is modified
- Context-Aware: Completions adapt based on the selected target
~/.cache/make-completion-enhanced.cache
The cache is automatically updated when the Makefile is modified.
The Bash completion uses the complete command and COMPREPLY array:
complete -F _make_completion_enhanced makeThe Zsh completion uses the compdef system:
#compdef makeBoth implementations share the same parsing logic and cache mechanism.
make-completion-enhanced/
├── Makefile # Example Makefile with annotations
├── make-completion-enhanced.bash # Bash completion script
├── _make-completion-enhanced # Zsh completion script
├── debian/ # Debian packaging files
│ ├── control
│ ├── install
│ ├── changelog
│ └── rules
└── README.md # This file
make debCreate a test Makefile and try the completions:
# Source the completion script
source make-completion-enhanced.bash
# Type and press TAB
make <TAB>
make run app=<TAB>-
Ensure the script is sourced in your shell config:
# Bash grep make-completion-enhanced ~/.bashrc # Zsh grep make-completion-enhanced ~/.zshrc
-
Verify the cache is being created:
ls -la ~/.cache/make-completion-enhanced.cache -
Check for syntax errors in your Makefile annotations:
awk '/^## /{print}' Makefile
Delete the cache manually:
rm ~/.cache/make-completion-enhanced.cacheVerify your Makefile syntax:
- Each
## PARAMmust be on its own line - Target definitions must use
## TARGET <name> - Values should be space-separated
Contributions are welcome! Please feel free to submit issues or pull requests.
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Commit your changes:
git commit -am 'Add new feature' - Push to the branch:
git push origin feature/my-feature - Submit a pull request
This project is open source and available under the MIT License.
- Original Author: [Your Name]
- Contributors: [List of contributors]
- Inspired by the need for better Make completion
- Built with standard shell tools (awk, grep, etc.)
- Compatible with modern Bash and Zsh shells