Skip to content

Instantly share code, notes, and snippets.

@GabrielVidal1
Created August 13, 2025 20:06
Show Gist options
  • Select an option

  • Save GabrielVidal1/7e819efd07838a5d8a6321ddd09177f2 to your computer and use it in GitHub Desktop.

Select an option

Save GabrielVidal1/7e819efd07838a5d8a6321ddd09177f2 to your computer and use it in GitHub Desktop.
make with args: a simple bash make wrapper to provide shell like arguments
#!/bin/bash
# kwake - A make wrapper that passes additional arguments as ARGS environment variable
# Usage: kwake [-v] <target> [args...]
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Default verbose mode (show echo)
VERBOSE=true
# Parse options
while getopts "v" opt; do
case $opt in
v)
VERBOSE=false
;;
\?)
echo -e "${RED}Invalid option: -$OPTARG${NC}" >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
# Check if Makefile exists
if [ ! -f "Makefile" ]; then
echo -e "${RED}Error: No Makefile found in current directory${NC}" >&2
exit 1
fi
# Check if at least one argument is provided
if [ $# -eq 0 ]; then
echo -e "${YELLOW}Usage: kwake [-v] <target> [args...]${NC}"
echo -e "${YELLOW} -v: Quiet mode (hide command echo)${NC}"
echo -e "${BLUE}Available targets:${NC}"
# Extract and display available targets from Makefile
grep "^[a-zA-Z0-9_-]*:" Makefile | sed 's/:.*$//' | sed 's/^/ - /'
exit 1
fi
# First argument is the make target
TARGET="$1"
shift
# Remaining arguments become ARGS
ARGS="$*"
# Display what we're doing (only if verbose)
if [ "$VERBOSE" = true ]; then
if [ -n "$ARGS" ]; then
echo -e "${GREEN}Running: make $TARGET ARGS=\"$ARGS\"${NC}"
else
echo -e "${GREEN}Running: make $TARGET${NC}"
fi
fi
# Execute make command
if [ -n "$ARGS" ]; then
ARGS="$ARGS" make "$TARGET"
else
make "$TARGET"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment