script: fix 'apply-color's

This commit is contained in:
2025-10-18 18:22:22 +02:00
parent 3a903205d9
commit 98fe49368b
18 changed files with 103 additions and 41 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg

View File

@@ -15,6 +15,16 @@ function log_info {
printf "\033[0;32mInfo:\033[0m $1\n" >&2
}
function color_ansi {
colorHex="$1"
local r=$((16#${colorHex:0:2}))
local g=$((16#${colorHex:2:2}))
local b=$((16#${colorHex:4:2}))
echo "\033[38;2;${r};${g};${b}m"
}
# remove leading '#' if present
if [[ $colorHex == \#* ]]; then
@@ -28,5 +38,5 @@ if ! [[ $colorHex =~ ^[0-9A-Fa-f]{6}$ ]]; then
fi
function log_success {
log_info "Applied primary color ${colorName} (${colorHex}) to \033[1;34m$1\033[0m"
log_info "Applied palette \033[1;34m${palette}\033[0m with primary color $(color_ansi $colorHex)${colorName} (#${colorHex})\033[0m to \033[1;34m$1\033[0m"
}

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg

13
fastfetch/apply-color Executable file
View File

@@ -0,0 +1,13 @@
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg
file="$path"/../fish/post.d/fetch.fish
sed -i -E "s/(set -g fetch_color\s+\"#)([0-9a-fA-F]{6})(\")/\1${colorHex}\3/" "$file" || {
log_error "Failed to edit ${file}"
exit 1
}
log_success "fastfetch"

View File

@@ -1,24 +1,56 @@
#!/bin/sh
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg
file="$path"/post.d/fetch.fish
sed -i 's/^\( set -g fetch_color "\)#\([0-9a-fA-F]\{6\}\)"/\1#'"${colorHex}"'"/' "$file" || {
log_error "Failed to edit ${file}"
exit 1
}
log_success "fastfetch"
# Also apply to omp here
file="$path"/../posh_theme.omp.json
sed -i 's/\("foreground":[[:space:]]*"\)#\([0-9a-fA-F]\{6\}\)"/\1#'"${colorHex}"'"/g' "$file" || {
targetTypes='["os", "session", "status"]'
python3 <<EOF
import json
import sys
data = None
with open("$file", "r") as f:
data = json.load(f)
def processSegments(segments):
for segment in segments:
if "type" in segment and segment["type"] in $targetTypes:
if "foreground" in segment:
segment["foreground"] = "#$colorHex"
def processTransientPrompt(transientPrompt):
if "foreground" in transientPrompt:
transientPrompt["foreground"] = "#$colorHex"
def process(obj):
if isinstance(obj, dict):
for k, v in obj.items():
if k == "segments" and isinstance(v, list):
processSegments(v)
elif k == "transient_prompt" and isinstance(v, dict):
processTransientPrompt(v)
else:
process(v)
elif isinstance(obj, list):
for item in obj:
process(item)
process(data)
if data is not None:
with open("$file", "w") as f:
json.dump(data, f, indent=4)
EOF
if [ $? -ne 0 ]; then
log_error "Failed to edit ${file}"
exit 1
}
fi
log_success "oh-my-posh"

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg

View File

@@ -123,7 +123,6 @@ spawn-sh-at-startup "config-switch niri"
// Idle
spawn-sh-at-startup "hypridle"
// Wallpaper
spawn-at-startup "wallpaper-daemon"
@@ -148,6 +147,9 @@ spawn-at-startup "kbuildsycoca6"
// Some other heavy apps
spawn-at-startup "sunshine"
// spawn-at-startup "spotify"
// spawn-at-startup "thunderbird"
// Quickshell must start after hypridle,
// otherwise Firefox cannot block idle when playing media
@@ -247,6 +249,19 @@ window-rule {
block-out-from "screen-capture"
}
// workspace "first"
// workspace "second"
// Startup in "second" workspace
window-rule {
// match at-startup=true app-id="Spotify"
// match at-startup=true app-id="thunderbird"
open-on-workspace "second"
}
// I love round corners
window-rule {
geometry-corner-radius 14

View File

@@ -26,7 +26,7 @@
"type": "session"
},
{
"foreground": "#89b4fa",
"foreground": "#94e2d5",
"properties": {
"folder_separator_icon": "/",
"style": "letter"
@@ -36,7 +36,7 @@
"type": "path"
},
{
"foreground": "#89b4fa",
"foreground": "#a6e3a1",
"powerline_symbol": "\ue0b1",
"properties": {
"branch_icon": " ",
@@ -50,7 +50,7 @@
"type": "git"
},
{
"foreground": "#89b4fa",
"foreground": "#f9e2af",
"powerline_symbol": "\ue0b1",
"template": " \ue235 {{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }} ",
"style": "powerline",
@@ -64,7 +64,7 @@
"newline": true,
"segments": [
{
"foreground": "#89b4fa",
"foreground": "#fab387",
"style": "plain",
"template": "\ue3bf ",
"type": "root"

View File

@@ -25,21 +25,16 @@ Singleton {
Logger.log("IpService", "Fetched IP: " + newIP);
if (newIP !== ip) {
ip = newIP;
countryCode = "N/A";
fetchGeoInfo(true); // Fetch geo info only if IP has changed
}
} else {
ip = "N/A";
countryCode = "N/A";
Logger.error("IpService", "IP response does not contain 'ip' field");
}
} catch (e) {
ip = "N/A";
countryCode = "N/A";
Logger.error("IpService", "Failed to parse IP response: " + e);
}
} else {
ip = "N/A";
countryCode = "N/A";
Logger.error("IpService", "Failed to fetch IP");
}
});
@@ -53,7 +48,8 @@ Singleton {
let url = geoURL + ip;
if (geoURLToken)
url += "?token=" + geoURLToken;
cacheFileAdapter.geoInfo = null
curl.fetch(url, function(success, data) {
if (success) {
try {
@@ -63,17 +59,13 @@ Singleton {
Logger.log("IpService", "Fetched country code: " + newCountryCode);
countryCode = newCountryCode;
} else {
countryCode = "N/A";
Logger.error("IpService", "Geo response does not contain 'country_code' field");
}
cacheFileAdapter.ip = ip;
cacheFileAdapter.geoInfo = response;
} catch (e) {
countryCode = "N/A";
Logger.error("IpService", "Failed to parse geo response: " + e);
}
} else {
countryCode = "N/A";
Logger.error("IpService", "Failed to fetch geo info");
}
SendNotification.show("New IP", `IP: ${ip}\nCountry: ${countryCode}`);

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg

View File

@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
path=$(dirname "$(readlink -f "$0")")
. "$path"/../.utils/apply-color-parse-arg