convert bundled defaults into an installable configuration template

This commit is contained in:
2026-07-13 16:44:50 +02:00
parent a894449d15
commit 1867a4c0a6
9 changed files with 128 additions and 26 deletions
+1 -4
View File
@@ -34,10 +34,7 @@ let package = Package(
exclude: [
"Models/PHEvent/README.md"
],
resources: [
.process("Models/PHConfig/config.toml"),
.process("Models/PHTheme/theme.toml"),
]
resources: [.copy("config")]
),
.testTarget(
name: "phbarTests",
@@ -0,0 +1,69 @@
import ArgumentParser
import Foundation
extension PHBar {
struct Install: ParsableCommand {
static let configuration = CommandConfiguration(
commandName: "install",
abstract: "Start the status bar.",
discussion: """
Launch the bar as a non-stopping background process.
This command is meant to be used for both testing and production.
When testing, you can provide the `--debug` flag to get visual
guidance that helps you configure the blocks and a verbose output from
the shell scripts to debug the behaviour.
"""
)
private var source: URL? {
Bundle.module.url(forResource: "config", withExtension: "")
}
private var destination: URL {
let environment = ProcessInfo.processInfo.environment
let homeDirectory = FileManager.default.homeDirectoryForCurrentUser
let standardConfigDirectory = homeDirectory.appending(path: ".config")
let xdgConfigDirectory = environment["XDG_CONFIG_HOME"]?.trimmingCharacters(
in: .whitespaces)
var candidateDirectory: URL
if let xdgConfigDirectory, xdgConfigDirectory.hasPrefix("/") {
candidateDirectory = URL(fileURLWithPath: xdgConfigDirectory)
} else if FileManager.default.fileExists(atPath: standardConfigDirectory.relativePath) {
candidateDirectory = standardConfigDirectory
} else {
candidateDirectory = homeDirectory
}
return candidateDirectory.appending(path: "phbar")
}
mutating func run() throws {
do {
guard let source else { throw PHBar.Error("Failed to locate bundled config") }
try FileManager.default.copyItem(at: source, to: destination)
try makeExecutable()
} catch {
throw PHBar.Error("Failed to create config directory", underlyingError: error)
}
throw CleanExit.message("Config directory created at \(destination.relativePath)")
}
private func makeExecutable() throws {
let scriptsDirectory = destination.appending(path: "scripts", directoryHint: .isDirectory)
let scripts = try FileManager.default.contentsOfDirectory(
atPath: scriptsDirectory.relativePath
)
for script in scripts {
let path = scriptsDirectory.appending(path: script)
var attributes: [FileAttributeKey: Any] = [:]
attributes[.posixPermissions] = 0o755 // rwxr-xr-x
try FileManager.default.setAttributes(attributes, ofItemAtPath: path.relativePath)
}
}
}
}
+1 -1
View File
@@ -39,7 +39,7 @@ struct PHBar: ParsableCommand {
the same command to start the bar automatically at login.
""",
version: "1.0.0",
subcommands: [Start.self, Refresh.self]
subcommands: [Start.self, Install.self]
)
}
+31
View File
@@ -0,0 +1,31 @@
[[block]]
name = "version"
style = "elevated"
[[block]]
name = "_space 14"
[[block]]
name = "attribution"
command = 'echo "by Panini House"'
text = "italic"
[[block]]
name = "_space"
[[block]]
name = "gesture"
[[block]]
name = "_space 14"
[[block]]
name = "clock"
refresh = 1
style = "elevated"
[[block]]
name = "greetings"
command = 'echo "􀟱 Hi $USER", welcome to phbar!'
text = "italic"
centered = true
@@ -6,19 +6,17 @@ theme = "default"
window = "default"
blocks = "default"
# Optional: override the theme, window, and/or block set per monitor.
# Optional: override the window and/or block set per monitor.
# - quoted numeric key → NSScreen index
# - string key → NSScreen.localizedName (stable across replugs)
# Precedence: monitor name → monitor index → the globals above.
# Either field may be omitted to inherit its global value.
#
# [monitor."1"]
# theme = "default"
# window = "bottom"
# blocks = "laptop"
#
# [monitor."DELL U2723QE"]
# theme = "external"
# window = "clock"
# blocks = "external"
@@ -32,6 +30,5 @@ blocks = "default"
# theme (e.g. `ACCENT = "#ff0000"`, then `color = "$ACCENT"` in the theme)
#
# [env]
# TEST = "ciao"
# TEST_2 = "hello world"
# PATH = "$PATH:/opt/homebrew/bin"
# MY_CUSTOM_VAR = "hello world"
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
echo "􀐬 $(date "+%a %d, %H:%M:%S")"
+12
View File
@@ -0,0 +1,12 @@
#!/bin/sh
text="Click me"
case $GESTURE in
"left_mouse_down") text="That's left mouse button!" ;;
"right_mouse_down") text="That's right mouse button!" ;;
"other_mouse_down") text="That's mouse button $GESTURE_INFO!" ;;
"scroll_wheel") text="Yes, you can even scroll!" ;;
esac
echo "􀭆 $text"
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
echo "phbar v$(phbar --version)"
@@ -8,39 +8,29 @@ anchor = "top"
height = 30
width = "100%"
[[window]]
name = "bottom"
anchor = "bottom"
height = 30
width = "100%"
[[text]]
name = "default"
font = "Comic Code"
font = "monospace"
size = 14
weight = "regular"
style = "normal"
offset = -0.5
offset = -1
[[text]]
name = "italic"
font = "Comic Code"
font = "monospace"
size = 14
weight = "regular"
style = "italic"
offset = -0.5
offset = -1
[[style]]
name = "default"
foreground = { color = "#aed3f3" }
background = { color = "#010408", alpha = 0.825 }
background = { color = "#010408" }
[[style]]
name = "floating"
foreground = { color = "#aed3f3" }
[[style]]
name = "tinted"
name = "elevated"
foreground = { color = "#aed3f3" }
background = { color = "#0f304a" }
padding = { left = 12.0, right = 12.0 }