-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.sh
More file actions
executable file
·40 lines (30 loc) · 1.05 KB
/
render.sh
File metadata and controls
executable file
·40 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# render.sh - Simple chezmoi template renderer
# Usage: ./render.sh [template-file]
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
usage() {
echo "Usage: $0 [template-file]"
echo ""
echo "Renders a chezmoi template file to stdout"
echo ""
echo "Examples:"
echo " $0 root/.chezmoi.toml.tmpl"
echo " $0 root/dot_gitconfig.tmpl"
}
if [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then
usage
exit 0
fi
TEMPLATE_FILE="$1"
if [[ ! -f "$SCRIPT_DIR/$TEMPLATE_FILE" ]]; then
echo "Error: Template file not found: $TEMPLATE_FILE" >&2
exit 1
fi
# Create a temporary directory and config
TEMP_DIR=$(mktemp -d)
trap 'rm -rf "$TEMP_DIR"' EXIT
# Render the config template using the repo's version
chezmoi execute-template --source="$SCRIPT_DIR/root" < "$SCRIPT_DIR/root/.chezmoi.toml.tmpl" > "$TEMP_DIR/chezmoi.toml"
# Use the rendered config to execute the template
chezmoi execute-template --config="$TEMP_DIR/chezmoi.toml" --source="$SCRIPT_DIR/root" < "$SCRIPT_DIR/$TEMPLATE_FILE"