66 lines
1.9 KiB
Bash
66 lines
1.9 KiB
Bash
#!/bin/sh
|
|
|
|
# shmake_utils.sh - Utility functions for shmake
|
|
# Author: Emilia Marigold
|
|
|
|
#=========================================================================================
|
|
# Get script directory (POSIX-compliant)
|
|
#=========================================================================================
|
|
get_script_dir()
|
|
{
|
|
script_path="$0"
|
|
|
|
case "$script_path" in
|
|
*/*) ;;
|
|
*)
|
|
resolved=$(command -v "$0" 2>/dev/null)
|
|
if [ -n "$resolved" ]; then
|
|
script_path="$resolved"
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
case "$script_path" in
|
|
/*) ;;
|
|
*) script_path="$(pwd)/$script_path" ;;
|
|
esac
|
|
|
|
printf "%s" "$(cd "$(dirname "$script_path")" && pwd)"
|
|
}
|
|
|
|
#=========================================================================================
|
|
# Safe input reading for POSIX sh
|
|
#=========================================================================================
|
|
read_input()
|
|
{
|
|
prompt="$1"
|
|
default="$2"
|
|
variable_name="$3"
|
|
|
|
if [ -n "$default" ]; then
|
|
printf "%s [%s]: " "$prompt" "$default"
|
|
else
|
|
printf "%s: " "$prompt"
|
|
fi
|
|
|
|
read -r input_val
|
|
|
|
if [ -z "$input_val" ]; then
|
|
input_val="$default"
|
|
fi
|
|
|
|
eval "$variable_name='$input_val'"
|
|
}
|
|
|
|
#=========================================================================================
|
|
# Check if running from project root
|
|
#=========================================================================================
|
|
check_project_root()
|
|
{
|
|
if [ ! -f "shmake_config/project.conf" ]; then
|
|
printf "Error: Not in a shmake project directory.\n"
|
|
printf "Run 'shmake init' first or cd into your project folder.\n"
|
|
exit 1
|
|
fi
|
|
}
|