feat(cli): impl quickstart and update config dir

This commit implements the komorebic quickstart command, adds a sample
komorebi.json and a sample skhdrc file which get built into the
komorebic binary, and updates the default config path on macOS to
$HOME/.config/komorebi
This commit is contained in:
LGUG2Z committed 2025-09-26 15:10:03 -07:00
1 parent 33c319ef61
commit 3792da1bb3
5 files changed
+216 -16

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
{
"$schema": "https://raw.githubusercontent.com/LGUG2Z/komorebi/v0.1.39/schema.json",
"app_specific_configuration_path": "$HOME/.config/komorebi/applications.json",
"cross_monitor_move_behaviour": "Insert",
"default_workspace_padding": 15,
"default_container_padding": 15,
"floating_window_aspect_ratio": "Widescreen",
"floating_layer_behaviour": "Float",
"resize_delta": 100,
"ignore_rules": [],
"floating_applications": [],
"manage_rules": [],
"monitors": [
{
"workspaces": [
{
"name": "I",
"layout": "BSP",
"initial_workspace_rules": [
// {
// "kind": "Exe",
// "id": "Zen",
// "matching_strategy": "Equals"
// }
]
},
{
"name": "II",
"layout": "VerticalStack"
},
{
"name": "III",
"layout": "HorizontalStack"
},
{
"name": "IV",
"layout": "UltrawideVerticalStack"
},
{
"name": "V",
"layout": "Rows"
},
{
"name": "VI",
"layout": "Grid"
},
{
"name": "VII",
"layout": "RightMainVerticalStack"
},
{
"name": "VIII",
"layout": "Scrolling"
}
]
}
]
}
+69
View File
@@ -0,0 +1,69 @@
# Focus windows
alt - h : komorebic focus left
alt - j : komorebic focus down
alt - k : komorebic focus up
alt - l : komorebic focus right
alt + shift - 0x21 : komorebic cycle-focus previous # 0x21 is [
alt + shift - 0x1E : komorebic cycle-focus next # 0x1E is ]
# Move windows
alt + shift - h : komorebic move left
alt + shift - j : komorebic move down
alt + shift - k : komorebic move up
alt + shift - l : komorebic move right
alt + shift - return : komorebic promote
# Stack windows
ctrl - left : komorebic stack left
ctrl - down : komorebic stack down
ctrl - up : komorebic stack up
ctrl - right : komorebic stack right
alt - 0x29 : komorebic unstack # 0x29 is ;
alt - 0x21 : komorebic cycle-stack previous # 0x21 is [
alt - 0x1E : komorebic cycle-stack next # 0x1E is ]
# Workspace layer
alt + shift - 0x29 : komorebic toggle-workspace-layer # 0x29 is ;
# Resize
alt - 0x18 : komorebic resize-axis horizontal increase # 0x18 is +
alt - 0x1B : komorebic resize-axis horizontal decrease # 0x1B is -
alt + shift - 0x18 : komorebic resize-axis vertical increase
alt + shift - 0x1B : komorebic resize-axis vertical decrease
# Manipulate windows
alt - t : komorebic toggle-float
alt + shift - t : komorebic toggle-workspace-float-override
alt + shift - f : komorebic toggle-monocle
# Window manager options
alt + shift - r : komorebic retile
alt - p : komorebic toggle-pause
alt - 0 : komorebic toggle-window-container-behaviour
# Layouts
alt - x : komorebic flip-layout horizontal
alt - y : komorebic flip-layout vertical
alt + shift - x : komorebic session-float-rule
# Workspaces
alt - 1 : komorebic focus-workspace 0
alt - 2 : komorebic focus-workspace 1
alt - 3 : komorebic focus-workspace 2
alt - 4 : komorebic focus-workspace 3
alt - 5 : komorebic focus-workspace 4
alt - 6 : komorebic focus-workspace 5
alt - 7 : komorebic focus-workspace 6
alt - 8 : komorebic focus-workspace 7
alt - 9 : komorebic focus-workspace 8
# Move windows across workspaces
alt + shift - 1 : komorebic move-to-workspace 0
alt + shift - 2 : komorebic move-to-workspace 1
alt + shift - 3 : komorebic move-to-workspace 2
alt + shift - 4 : komorebic move-to-workspace 3
alt + shift - 5 : komorebic move-to-workspace 4
alt + shift - 6 : komorebic move-to-workspace 5
alt + shift - 7 : komorebic move-to-workspace 6
alt + shift - 8 : komorebic move-to-workspace 7
alt + shift - 9 : komorebic move-to-workspace 8
+16 -9
View File
@@ -74,17 +74,24 @@ pub mod workspace;
lazy_static! {
pub static ref HOME_DIR: PathBuf = {
std::env::var("KOMOREBI_CONFIG_HOME").map_or_else(|_| dirs::home_dir().expect("there is no home directory"), |home_path| {
let home = home_path.replace_env();
std::env::var("KOMOREBI_CONFIG_HOME").map_or_else(
|_| {
dirs::home_dir()
.expect("there is no home directory")
.join(".config")
.join("komorebi")
},
|home_path| {
let home = home_path.replace_env();
assert!(
home.is_dir(),
"$Env:KOMOREBI_CONFIG_HOME is set to '{home_path}', which is not a valid directory"
);
assert!(
home.is_dir(),
"$KOMOREBI_CONFIG_HOME is set to '{home_path}', which is not a valid directory"
);
home
})
home
},
)
};
pub static ref DATA_DIR: PathBuf = dirs::data_local_dir()
.expect("there is no local data directory")
+1 -1
View File
@@ -89,7 +89,7 @@ impl Default for Workspace {
workspace_padding: None,
container_padding: None,
resize_dimensions: vec![],
layout: Layout::Default(DefaultLayout::UltrawideVerticalStack),
layout: Layout::Default(DefaultLayout::BSP),
work_area_offset: None,
latest_layout: vec![],
layout_flip: None,
+72 -6
View File
@@ -39,7 +39,7 @@ lazy_static! {
static ref HAS_CUSTOM_CONFIG_HOME: AtomicBool = AtomicBool::new(false);
static ref HOME_DIR: PathBuf = {
std::env::var("KOMOREBI_CONFIG_HOME").map_or_else(
|_| dirs::home_dir().expect("there is no home directory"),
|_| dirs::home_dir().expect("there is no home directory").join(".config").join("komorebi"),
|home_path| {
let home = home_path.replace_env();
if home.as_path().is_dir() {
@@ -47,7 +47,7 @@ lazy_static! {
home
} else {
panic!(
"$Env:KOMOREBI_CONFIG_HOME is set to '{home_path}', which is not a valid directory",
"$KOMOREBI_CONFIG_HOME is set to '{home_path}', which is not a valid directory",
);
}
},
@@ -613,13 +613,11 @@ struct Opts {
enum SubCommand {
#[clap(hide = true)]
Docgen,
// /// Gather example configurations for a new-user quickstart
// Quickstart,
/// Gather example configurations for a new-user quickstart
Quickstart,
/// Start komorebi.exe as a background process
Start(Start),
/// Stop the komorebi.exe process and restore all hidden windows
// komorebi for Windows signature
// Stop(Stop),
Stop(Stop),
// /// Kill background processes started by komorebic
// Kill(Kill),
@@ -1177,6 +1175,74 @@ fn main() -> eyre::Result<()> {
}
}
}
SubCommand::Quickstart => {
fn write_file_with_prompt(
path: &PathBuf,
content: &str,
created_files: &mut Vec<String>,
) -> eyre::Result<()> {
if path.exists() {
print!(
"{} will be overwritten, do you want to continue? (y/N): ",
path.display()
);
std::io::stdout().flush()?;
let mut input = String::new();
std::io::stdin().read_line(&mut input)?;
let trimmed = input.trim().to_lowercase();
if trimmed == "y" || trimmed == "yes" {
std::fs::write(path, content)?;
created_files.push(path.display().to_string());
} else {
println!("Skipping {}", path.display());
}
} else {
std::fs::write(path, content)?;
created_files.push(path.display().to_string());
}
Ok(())
}
let local_appdata_dir = dirs::data_local_dir().expect("could not find localdata dir");
let data_dir = local_appdata_dir.join("komorebi");
std::fs::create_dir_all(&*HOME_DIR)?;
std::fs::create_dir_all(data_dir)?;
let mut komorebi_json = include_str!("../../docs/komorebi.example.json").to_string();
if std::env::var("KOMOREBI_CONFIG_HOME").is_ok() {
komorebi_json =
komorebi_json.replace("Env:USERPROFILE", "Env:KOMOREBI_CONFIG_HOME");
}
let komorebi_path = HOME_DIR.join("komorebi.json");
let applications_path = HOME_DIR.join("applications.json");
let skhdrc_path = HOME_DIR.join("skhdrc");
let mut written_files = Vec::new();
write_file_with_prompt(&komorebi_path, &komorebi_json, &mut written_files)?;
let applications_json = include_str!("../applications.json");
write_file_with_prompt(&applications_path, applications_json, &mut written_files)?;
let whkdrc = include_str!("../../docs/skhdrc.sample");
write_file_with_prompt(&skhdrc_path, whkdrc, &mut written_files)?;
if written_files.is_empty() {
println!("\nNo files were written.")
} else {
println!(
"\nThe following example files were written:\n{}",
written_files.join("\n")
);
}
println!("\nYou can now run: komorebic start");
println!(
"\nIf you have skhd hotkey daemon installed, you can also run: skhd --config {}",
skhdrc_path.display()
);
}
SubCommand::Start(arg) => {
let mut command = &mut Command::new("komorebi");