convert bundled defaults into an installable configuration template
This commit is contained in:
+1
-4
@@ -34,10 +34,7 @@ let package = Package(
|
|||||||
exclude: [
|
exclude: [
|
||||||
"Models/PHEvent/README.md"
|
"Models/PHEvent/README.md"
|
||||||
],
|
],
|
||||||
resources: [
|
resources: [.copy("config")]
|
||||||
.process("Models/PHConfig/config.toml"),
|
|
||||||
.process("Models/PHTheme/theme.toml"),
|
|
||||||
]
|
|
||||||
),
|
),
|
||||||
.testTarget(
|
.testTarget(
|
||||||
name: "phbarTests",
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,7 +39,7 @@ struct PHBar: ParsableCommand {
|
|||||||
the same command to start the bar automatically at login.
|
the same command to start the bar automatically at login.
|
||||||
""",
|
""",
|
||||||
version: "1.0.0",
|
version: "1.0.0",
|
||||||
subcommands: [Start.self, Refresh.self]
|
subcommands: [Start.self, Install.self]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
window = "default"
|
||||||
blocks = "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
|
# - quoted numeric key → NSScreen index
|
||||||
# - string key → NSScreen.localizedName (stable across replugs)
|
# - string key → NSScreen.localizedName (stable across replugs)
|
||||||
# Precedence: monitor name → monitor index → the globals above.
|
# Precedence: monitor name → monitor index → the globals above.
|
||||||
# Either field may be omitted to inherit its global value.
|
# Either field may be omitted to inherit its global value.
|
||||||
#
|
#
|
||||||
# [monitor."1"]
|
# [monitor."1"]
|
||||||
# theme = "default"
|
|
||||||
# window = "bottom"
|
# window = "bottom"
|
||||||
# blocks = "laptop"
|
# blocks = "laptop"
|
||||||
#
|
#
|
||||||
# [monitor."DELL U2723QE"]
|
# [monitor."DELL U2723QE"]
|
||||||
# theme = "external"
|
|
||||||
# window = "clock"
|
# window = "clock"
|
||||||
# blocks = "external"
|
# blocks = "external"
|
||||||
|
|
||||||
@@ -32,6 +30,5 @@ blocks = "default"
|
|||||||
# theme (e.g. `ACCENT = "#ff0000"`, then `color = "$ACCENT"` in the theme)
|
# theme (e.g. `ACCENT = "#ff0000"`, then `color = "$ACCENT"` in the theme)
|
||||||
#
|
#
|
||||||
# [env]
|
# [env]
|
||||||
# TEST = "ciao"
|
|
||||||
# TEST_2 = "hello world"
|
|
||||||
# PATH = "$PATH:/opt/homebrew/bin"
|
# PATH = "$PATH:/opt/homebrew/bin"
|
||||||
|
# MY_CUSTOM_VAR = "hello world"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo " $(date "+%a %d, %H:%M:%S")"
|
||||||
@@ -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"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "phbar v$(phbar --version)"
|
||||||
@@ -8,39 +8,29 @@ anchor = "top"
|
|||||||
height = 30
|
height = 30
|
||||||
width = "100%"
|
width = "100%"
|
||||||
|
|
||||||
[[window]]
|
|
||||||
name = "bottom"
|
|
||||||
anchor = "bottom"
|
|
||||||
height = 30
|
|
||||||
width = "100%"
|
|
||||||
|
|
||||||
[[text]]
|
[[text]]
|
||||||
name = "default"
|
name = "default"
|
||||||
font = "Comic Code"
|
font = "monospace"
|
||||||
size = 14
|
size = 14
|
||||||
weight = "regular"
|
weight = "regular"
|
||||||
style = "normal"
|
style = "normal"
|
||||||
offset = -0.5
|
offset = -1
|
||||||
|
|
||||||
[[text]]
|
[[text]]
|
||||||
name = "italic"
|
name = "italic"
|
||||||
font = "Comic Code"
|
font = "monospace"
|
||||||
size = 14
|
size = 14
|
||||||
weight = "regular"
|
weight = "regular"
|
||||||
style = "italic"
|
style = "italic"
|
||||||
offset = -0.5
|
offset = -1
|
||||||
|
|
||||||
[[style]]
|
[[style]]
|
||||||
name = "default"
|
name = "default"
|
||||||
foreground = { color = "#aed3f3" }
|
foreground = { color = "#aed3f3" }
|
||||||
background = { color = "#010408", alpha = 0.825 }
|
background = { color = "#010408" }
|
||||||
|
|
||||||
[[style]]
|
[[style]]
|
||||||
name = "floating"
|
name = "elevated"
|
||||||
foreground = { color = "#aed3f3" }
|
|
||||||
|
|
||||||
[[style]]
|
|
||||||
name = "tinted"
|
|
||||||
foreground = { color = "#aed3f3" }
|
foreground = { color = "#aed3f3" }
|
||||||
background = { color = "#0f304a" }
|
background = { color = "#0f304a" }
|
||||||
padding = { left = 12.0, right = 12.0 }
|
padding = { left = 12.0, right = 12.0 }
|
||||||
Reference in New Issue
Block a user