Merge claude/1
This commit is contained in:
commit
734ca2940c
33
init.sh
33
init.sh
@ -338,14 +338,23 @@ initUpdateConfigOption() {
|
|||||||
for config_file in "$category_dir"/*; do
|
for config_file in "$category_dir"/*; do
|
||||||
if [ -f "$config_file" ] && [[ ! "$config_file" =~ \.category$ ]]; then
|
if [ -f "$config_file" ] && [[ ! "$config_file" =~ \.category$ ]]; then
|
||||||
if grep -q "^$config_option=" "$config_file"; then
|
if grep -q "^$config_option=" "$config_file"; then
|
||||||
local escaped_value=$(printf '%s\n' "$config_value" | sed -e 's/[\/&]/\\&/g')
|
# Use SOH (\x01) as the s-command delimiter — it can't appear
|
||||||
|
# in text-based config values or comments, so no field needs
|
||||||
|
# to escape the delimiter. The replacement field DOES need
|
||||||
|
# `&` (whole-match insertion) and `\` (escape char) neutralised
|
||||||
|
# in BOTH the value AND the comment — comments like
|
||||||
|
# `# Installation Mode - ...[release|git|local]` previously
|
||||||
|
# broke the `|`-delimited form with "unknown option to `s'".
|
||||||
|
local DELIM=$'\x01'
|
||||||
|
local escaped_value=$(printf '%s' "$config_value" | sed -e 's/[\\&]/\\&/g')
|
||||||
local original_line=$(grep "^$config_option=" "$config_file")
|
local original_line=$(grep "^$config_option=" "$config_file")
|
||||||
local comment_part=$(echo "$original_line" | sed -n "s|^$config_option=[^#]*\(#.*\)|\1|p")
|
local comment_part=$(echo "$original_line" | sed -n "s|^$config_option=[^#]*\(#.*\)|\1|p")
|
||||||
|
local escaped_comment=$(printf '%s' "$comment_part" | sed -e 's/[\\&]/\\&/g')
|
||||||
|
|
||||||
if [[ -n "$comment_part" ]]; then
|
if [[ -n "$comment_part" ]]; then
|
||||||
sed -i "s|^$config_option=.*|$config_option=$escaped_value $comment_part|" "$config_file"
|
sed -i "s${DELIM}^$config_option=.*${DELIM}$config_option=$escaped_value $escaped_comment${DELIM}" "$config_file"
|
||||||
else
|
else
|
||||||
sed -i "s|^$config_option=.*|$config_option=$escaped_value|" "$config_file"
|
sed -i "s${DELIM}^$config_option=.*${DELIM}$config_option=$escaped_value${DELIM}" "$config_file"
|
||||||
fi
|
fi
|
||||||
source "$config_file"
|
source "$config_file"
|
||||||
return 0
|
return 0
|
||||||
@ -1249,18 +1258,24 @@ commandUpdateConfigOption() {
|
|||||||
for config_file in "$category_dir"/*; do
|
for config_file in "$category_dir"/*; do
|
||||||
if [ -f "$config_file" ] && [[ ! "$config_file" =~ \.category$ ]]; then
|
if [ -f "$config_file" ] && [[ ! "$config_file" =~ \.category$ ]]; then
|
||||||
if grep -q "^$config_option=" "$config_file"; then
|
if grep -q "^$config_option=" "$config_file"; then
|
||||||
# Escape special characters in the config value to prevent sed issues
|
# Use SOH (\x01) as the s-command delimiter — it can't appear
|
||||||
local escaped_value=$(printf '%s\n' "$config_value" | sed -e 's/[\/&]/\\&/g')
|
# in text-based config values or comments, so no field needs
|
||||||
|
# to escape the delimiter. The replacement field DOES need
|
||||||
|
# `&` (whole-match insertion) and `\` (escape char) neutralised
|
||||||
|
# in BOTH the value AND the comment — comments like
|
||||||
|
# `# Installation Mode - ...[release|git|local]` previously
|
||||||
|
# broke the `|`-delimited form with "unknown option to `s'".
|
||||||
|
local DELIM=$'\x01'
|
||||||
|
local escaped_value=$(printf '%s' "$config_value" | sed -e 's/[\\&]/\\&/g')
|
||||||
|
|
||||||
# Extract the comment part first (everything after the first #)
|
# Extract the comment part first (everything after the first #)
|
||||||
local original_line=$(grep "^$config_option=" "$config_file")
|
local original_line=$(grep "^$config_option=" "$config_file")
|
||||||
local comment_part=$(echo "$original_line" | sed -n "s|^$config_option=[^#]*\(#.*\)|\1|p")
|
local comment_part=$(echo "$original_line" | sed -n "s|^$config_option=[^#]*\(#.*\)|\1|p")
|
||||||
|
local escaped_comment=$(printf '%s' "$comment_part" | sed -e 's/[\\&]/\\&/g')
|
||||||
# Replace the value, preserving comment if it existed
|
|
||||||
if [[ -n "$comment_part" ]]; then
|
if [[ -n "$comment_part" ]]; then
|
||||||
sed -i "s|^$config_option=.*|$config_option=$escaped_value $comment_part|" "$config_file"
|
sed -i "s${DELIM}^$config_option=.*${DELIM}$config_option=$escaped_value $escaped_comment${DELIM}" "$config_file"
|
||||||
else
|
else
|
||||||
sed -i "s|^$config_option=.*|$config_option=$escaped_value|" "$config_file"
|
sed -i "s${DELIM}^$config_option=.*${DELIM}$config_option=$escaped_value${DELIM}" "$config_file"
|
||||||
fi
|
fi
|
||||||
source "$config_file"
|
source "$config_file"
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user