This commit is contained in:
2026-10-10 23:12:15 -04:00
parent 1654e0f867
commit c21a41930b
5 changed files with 6326 additions and 19 deletions
+43 -14
View File
@@ -44,20 +44,49 @@ function findJJSource {
export JJ_SOURCE_DIR=$(findJJSource)
if ! JJ_DATA_DIR=$(bun -e '
const fs = require("fs");
const YAML = require(`${process.env.JJ_SOURCE_DIR}/node_modules/js-yaml`);
try {
const config = YAML.load(fs.readFileSync("jj.yaml", "utf8"));
if (typeof config?.dataFolder !== "string" || !config.dataFolder.trim()) {
throw new Error("jj.yaml must contain a non-empty dataFolder string");
}
process.stdout.write(config.dataFolder);
} catch (error) {
console.error(`[jj] ${error.message}`);
process.exit(1);
}
'); then
readJJDataDir() {
local line value
local keyPattern='^dataFolder:[[:space:]]*(.*)$'
local doubleQuotedPattern='^"([^"\\]*)"[[:space:]]*(#.*)?$'
local singleQuotedPattern="^'([^']*)'[[:space:]]*(#.*)?$"
if [[ ! -r jj.yaml ]]; then
echo "[jj] Cannot read jj.yaml in the current directory" >&2
return 1
fi
while IFS= read -r line || [[ -n "$line" ]]; do
if [[ ! "$line" =~ $keyPattern ]]; then
continue
fi
value="${BASH_REMATCH[1]}"
if [[ "$value" =~ $doubleQuotedPattern || "$value" =~ $singleQuotedPattern ]]; then
value="${BASH_REMATCH[1]}"
elif [[ "$value" == \"* || "$value" == \'* ]]; then
break
else
# YAML comments start at a # preceded by whitespace.
value="${value%%[[:space:]]#*}"
value="${value%"${value##*[![:space:]]}"}"
case "$value" in
\#*|\[*|\{*|\|*|\>*|\&*|\**|\!*|null|Null|NULL|~|true|True|TRUE|false|False|FALSE) break ;;
esac
if [[ "$value" =~ ^[-+]?([0-9]+([.][0-9]*)?|[.][0-9]+)([eE][-+]?[0-9]+)?$ ]]; then
break
fi
fi
if [[ -n "${value//[[:space:]]/}" ]]; then
printf '%s' "$value"
return 0
fi
break
done < jj.yaml
echo "[jj] jj.yaml must contain a non-empty dataFolder path (plain or quoted, without YAML escapes)" >&2
return 1
}
if ! JJ_DATA_DIR=$(readJJDataDir); then
exit 1
fi
if [[ "$JJ_DATA_DIR" == "~" ]]; then