use global flag to load config

This commit is contained in:
Daylin Morgan 2024-11-15 09:20:44 -06:00
parent 884cb9c68c
commit 44b25bdf70
Signed by: daylin
GPG key ID: 950D13E9719334AD
5 changed files with 22 additions and 15 deletions

View file

@ -48,7 +48,7 @@
pname = "hyprman";
version = "unstable";
src = cleanSource ./.;
nimbleDepsHash = "sha256-OqyB91B9bjyZXavb4Ikv2wMpH8UPsTGn2dmqiX8IFT0=";
nimbleDepsHash = "sha256-tDhf7CrHtgtu9NNFzp3swnfeMYBFrvHsFwR0JeYul7Q=";
};
});
formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);

View file

@ -13,4 +13,4 @@ bin = @["hyprman"]
requires "nim >= 2.0.8"
requires "yaml"
requires "jsony"
requires "https://github.com/daylinmorgan/hwylterm#65a952e"
requires "https://github.com/daylinmorgan/hwylterm#f1cc95f8"

View file

@ -3,12 +3,12 @@
"packages": {
"hwylterm": {
"version": "0.1.0",
"vcsRevision": "65a952e9f0d75659d39f8a3b146753e291ee0a66",
"vcsRevision": "f1cc95f86edcc00665fc8280f57edc0e83d461f9",
"url": "https://github.com/daylinmorgan/hwylterm",
"downloadMethod": "git",
"dependencies": [],
"checksums": {
"sha1": "10894d492bbe1d0ea32ee9bb0686abfcd3b0b0fe"
"sha1": "433522bac3b8f3caae252a1a42867ed8dc91f4d2"
}
},
"jsony": {

View file

@ -1,6 +1,6 @@
## hyprman, the hyprland companion
import std/[osproc, strformat]
import std/[os, osproc, strformat]
import hwylterm/hwylcli
import ./[
hyprland,
@ -10,8 +10,17 @@ import ./[
hwylCli:
name "hyprman"
flags:
[global]
config:
i configPath
T string
? "path to config file"
* (getConfigDir() / "hyprman" / "config.yml")
- c
preSub:
config.load(configPath)
subcommands:
[mako]
... "interact with mako"
flags:
@ -19,7 +28,6 @@ hwylCli:
T int
? "# of notifications"
* 10
- c
json:
? "output as json"
- j

View file

@ -20,12 +20,13 @@ type
`no-client`*: string
`default-icon`*: string
proc loadConfig*(): Config =
let configPath = getConfigDir() / "hyprman" / "config.yml"
if fileExists(configPath):
var s = newFileStream(configPath)
load(s, result)
result.wallpapers = expandTilde(result.wallpapers)
var config*: Config
proc load*(c: var Config, p: string) =
if fileExists(p):
var s = newFileStream(p)
load(s, c)
c.wallpapers = expandTilde(c.wallpapers)
func pickIcon*(
c: Config,
@ -35,5 +36,3 @@ func pickIcon*(
if class in k: result = v
if result == "":
result = c.`default-icon`
let config* = loadConfig()