dev-mirror: fix cargo official/duplicate handling, sed-free line set, gemrc safety
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@
|
||||
},
|
||||
"cargo": {
|
||||
"china": "sparse+https://rsproxy.cn/index/",
|
||||
"official": "sparse+https://index.crates.io/"
|
||||
"official": ""
|
||||
},
|
||||
"go": {
|
||||
"china": "https://goproxy.cn,direct",
|
||||
|
||||
+18
-8
@@ -26,11 +26,9 @@ cn_dm_set_line() {
|
||||
|
||||
mkdir -p "${file%/*}"
|
||||
touch "$file"
|
||||
if grep -qE "$match" "$file"; then
|
||||
sed -i -E "s|$match.*|$line|" "$file"
|
||||
else
|
||||
echo "$line" >> "$file"
|
||||
fi
|
||||
grep -vE "$match" "$file" > "$file.omarchycn-tmp" || true
|
||||
printf '%s\n' "$line" >> "$file.omarchycn-tmp"
|
||||
mv "$file.omarchycn-tmp" "$file"
|
||||
}
|
||||
|
||||
cn_dm_get_npm() { grep -sE '^registry=' "$HOME/.npmrc" | cut -d= -f2- || true; }
|
||||
@@ -71,7 +69,13 @@ cn_dm_set_cargo() {
|
||||
mkdir -p "${f%/*}"
|
||||
touch "$f"
|
||||
sed -i '/^# OmarchyCN dev-mirror begin$/,/^# OmarchyCN dev-mirror end$/d' "$f"
|
||||
if [[ -n $url ]]; then
|
||||
if [[ -z $url ]]; then
|
||||
return 0
|
||||
fi
|
||||
if grep -q '^\[source\.crates-io\]' "$f"; then
|
||||
echo "cargo: $f already defines [source.crates-io]; edit it manually" >&2
|
||||
return 1
|
||||
fi
|
||||
cat >> "$f" <<EOF
|
||||
# OmarchyCN dev-mirror begin
|
||||
[source.crates-io]
|
||||
@@ -81,7 +85,6 @@ replace-with = "omarchycn"
|
||||
registry = "$url"
|
||||
# OmarchyCN dev-mirror end
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
cn_dm_get_go() { grep -sE '^GOPROXY=' "$HOME/.config/go/env" | cut -d= -f2- || true; }
|
||||
@@ -90,7 +93,14 @@ cn_dm_set_go() { cn_dm_set_line "$HOME/.config/go/env" '^GOPROXY=' "GOPROXY=$1";
|
||||
cn_dm_get_gem() { grep -sE '^- ' "$HOME/.gemrc" | head -1 | sed 's/^- //' || true; }
|
||||
|
||||
cn_dm_set_gem() {
|
||||
cat > "$HOME/.gemrc" <<EOF
|
||||
local f="$HOME/.gemrc"
|
||||
|
||||
if [[ -s $f ]] && ! grep -q '^# OmarchyCN dev-mirror managed$' "$f"; then
|
||||
echo "gem: $f has existing user content; set :sources: manually" >&2
|
||||
return 1
|
||||
fi
|
||||
cat > "$f" <<EOF
|
||||
# OmarchyCN dev-mirror managed
|
||||
---
|
||||
:sources:
|
||||
- $1
|
||||
|
||||
Reference in New Issue
Block a user