This commit is contained in:
Lysec
2026-04-19 09:22:38 +02:00
2 changed files with 64 additions and 48 deletions
+45 -29
View File
@@ -535,56 +535,72 @@ zathura)
;;
starship)
# Check if the nested starship config exists first
if [ -f "$HOME/.config/starship/starship.toml" ]; then
PALETTE_FILE="$HOME/.cache/noctalia/starship-palette.toml"
# Respect STARSHIP_CONFIG env var, then fall back to standard lookup order
if [ -n "$STARSHIP_CONFIG" ]; then
CONFIG_FILE="$STARSHIP_CONFIG"
elif [ -f "$HOME/.config/starship.toml" ]; then
CONFIG_FILE="$HOME/.config/starship.toml"
elif [ -f "$HOME/.config/starship/starship.toml" ]; then
CONFIG_FILE="$HOME/.config/starship/starship.toml"
else
# Fallback to the default path
CONFIG_FILE="$HOME/.config/starship.toml"
fi
# Check if the generated palette file exists
if [ ! -f "$PALETTE_FILE" ]; then
echo "Error: Starship palette file not found at $PALETTE_FILE" >&2
exit 1
return 1
fi
MARKER_BEGIN="# >>> NOCTALIA STARSHIP PALETTE >>>"
MARKER_END="# <<< NOCTALIA STARSHIP PALETTE <<<"
MARKER_BEGIN='# >>> NOCTALIA STARSHIP PALETTE >>>'
MARKER_END='# <<< NOCTALIA STARSHIP PALETTE <<<'
# Create config file if it doesn't exist
# Create config file from scratch if it doesn't exist yet
if [ ! -f "$CONFIG_FILE" ]; then
mkdir -p "$(dirname "$CONFIG_FILE")"
echo 'palette = "noctalia"' > "$CONFIG_FILE"
echo "" >> "$CONFIG_FILE"
echo "$MARKER_BEGIN" >> "$CONFIG_FILE"
cat "$PALETTE_FILE" >> "$CONFIG_FILE"
echo "$MARKER_END" >> "$CONFIG_FILE"
exit 0
{
printf 'palette = "noctalia"\n\n'
printf '%s\n' "$MARKER_BEGIN"
cat "$PALETTE_FILE"
printf '%s\n' "$MARKER_END"
} > "$CONFIG_FILE"
return 0
fi
# 1. Set palette = "noctalia" at top level
if grep -qE '^palette\s*=' "$CONFIG_FILE"; then
sed -i -E 's/^palette\s*=.*/palette = "noctalia"/' "$CONFIG_FILE"
else
# Insert after schema line if present, otherwise at line 1
if grep -qE '^\"\$schema\"' "$CONFIG_FILE"; then
sed -i '/^\"\$schema\"/a palette = "noctalia"' "$CONFIG_FILE"
# Follow symlinks so we edit the real file (safe for stow / dotfile managers)
if [ -L "$CONFIG_FILE" ]; then
CONFIG_FILE="$(readlink -f "$CONFIG_FILE")"
fi
# Set or insert top-level palette = "noctalia"
if grep -qE '^[[:space:]]*palette[[:space:]]*=' "$CONFIG_FILE"; then
sed -i -E 's/^([[:space:]]*)palette([[:space:]]*)=.*/\1palette\2= "noctalia"/' "$CONFIG_FILE"
elif grep -qE '^[[:space:]]*"\$schema"' "$CONFIG_FILE"; then
sed -i '/^[[:space:]]*"\$schema"/a palette = "noctalia"' "$CONFIG_FILE"
else
sed -i '1i palette = "noctalia"' "$CONFIG_FILE"
fi
fi
# 2. Remove existing noctalia palette block (between markers)
# Remove existing palette block using awk for literal string matching
# (avoids sed misinterpreting >, #, or other chars in the markers as regex)
if grep -qF "$MARKER_BEGIN" "$CONFIG_FILE"; then
sed -i "/$(echo "$MARKER_BEGIN" | sed 's/[[\.*^$()+?{|]/\\&/g')/,/$(echo "$MARKER_END" | sed 's/[[\.*^$()+?{|]/\\&/g')/d" "$CONFIG_FILE"
awk -v begin="$MARKER_BEGIN" -v end="$MARKER_END" '
$0 == begin { skip = 1; next }
$0 == end { skip = 0; next }
!skip
' "$CONFIG_FILE" > "${CONFIG_FILE}.noctalia.tmp" \
&& mv "${CONFIG_FILE}.noctalia.tmp" "$CONFIG_FILE"
fi
# 3. Append the new palette block
echo "" >> "$CONFIG_FILE"
echo "$MARKER_BEGIN" >> "$CONFIG_FILE"
cat "$PALETTE_FILE" >> "$CONFIG_FILE"
echo "$MARKER_END" >> "$CONFIG_FILE"
# Append fresh palette block, ensuring a clean newline boundary
{
printf '\n%s\n' "$MARKER_BEGIN"
cat "$PALETTE_FILE"
# Guard: ensure palette file ends with newline before closing marker
tail -c1 "$PALETTE_FILE" | grep -q $'\n' || printf '\n'
printf '%s\n' "$MARKER_END"
} >> "$CONFIG_FILE"
;;
*)
Generated
+3 -3
View File
@@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1775710090,
"narHash": "sha256-ar3rofg+awPB8QXDaFJhJ2jJhu+KqN/PRCXeyuXR76E=",
"lastModified": 1776169885,
"narHash": "sha256-l/iNYDZ4bGOAFQY2q8y5OAfBBtrDAaPuRQqWaFHVRXM=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "4c1018dae018162ec878d42fec712642d214fdfa",
"rev": "4bd9165a9165d7b5e33ae57f3eecbcb28fb231c9",
"type": "github"
},
"original": {