blob: 7d7736b9f010c8a274a4431fd4b4122811179ba9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// nixos-config - My current NixOS configuration
//
// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of my nixos-config.
//
// You should have received a copy of the License along with this program.
// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
use std::fs;
use anyhow::Context;
use clap::Parser;
pub mod cli;
pub mod key_map;
pub mod wayland;
use crate::{cli::Args, key_map::KeyMap};
fn main() -> Result<(), anyhow::Error> {
let args = Args::parse();
let keymap_path = &args.keymap.canonicalize().with_context(|| {
format!(
"Failed to canonicalize kepmay path: '{}'",
args.keymap.display()
)
})?;
let config = {
let keymap_file = fs::read_to_string(keymap_path).with_context(|| {
format!(
"Failed to open keymap file at: '{}'.",
keymap_path.display()
)
})?;
let keymap: KeyMap = keymap_file.parse().with_context(|| {
format!("Failed to parse keymap file at: {}", keymap_path.display())
})?;
keymap
};
match args.command {
cli::SubCommand::Init {} => {
println!("{config}");
// println!("Commands:");
for mut command in config.to_commands(keymap_path)? {
// println!("{command:?}");
let status = command
.status()
.with_context(|| format!("Failed to run command: '{command:?}'"))?;
if !status.success() {
eprintln!("Command ('{command:?}') returned with non zero exit code: {status}");
}
}
}
cli::SubCommand::ShowHelp {} => wayland::main(config)?,
}
Ok(())
}
|