Compare commits

...

3 commits

Author SHA1 Message Date
Penelope Gwen
8e9567e6e0 cli cleanup and implement completion generation 2026-01-24 13:46:14 -08:00
Penelope Gwen
de96002fdf clean up imports 2026-01-24 12:07:31 -08:00
Penelope Gwen
41783fe0da clean up imports 2026-01-24 12:06:59 -08:00
15 changed files with 81 additions and 46 deletions

12
Cargo.lock generated
View file

@ -321,6 +321,15 @@ dependencies = [
"strsim",
]
[[package]]
name = "clap_complete"
version = "4.5.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "430b4dc2b5e3861848de79627b2bedc9f3342c7da5173a14eaa5d0f8dc18ae5d"
dependencies = [
"clap",
]
[[package]]
name = "clap_derive"
version = "4.5.45"
@ -1827,9 +1836,10 @@ dependencies = [
[[package]]
name = "sway-de-utils"
version = "0.1.6"
version = "0.1.7"
dependencies = [
"clap",
"clap_complete",
"confy",
"dialog",
"env_logger",

View file

@ -1,10 +1,11 @@
[package]
name = "sway-de-utils"
version = "0.1.6"
version = "0.1.7"
authors = ["Penelope Gwen <support@pogmom.me>"]
edition = "2024"
license-file = "LICENSE.md"
description = "A collection of utility commands which help manage a multiple-workspace setup in Sway"
build="build.rs"
[[bin]]
name = "sdu"
@ -32,6 +33,17 @@ watchexec = "8.0.1"
watchexec-events = "6.0.0"
xdg = "3.0.0"
[build-dependencies]
clap = { version = "4.5.45", features = ["derive", "cargo"] }
clap_complete = "4.5.65"
[package.metadata.deb]
#conflicts = ["sway-profiles"]
changelog = "debian/changelog"
assets = [
"$auto",
["target/release/build/sway-de-utils-*/out/sdu.bash", "/usr/share/bash-completion/completions/", "644"],
["target/release/build/sway-de-utils-*/out/_sdu", "/usr/share/zsh/vendor_completions/", "644"],
["target/release/build/sway-de-utils-*/out/sdu.fish", "/usr/share/fish/vendor_completions.d/", "644"],
["target/release/build/sway-de-utils-*/out/sdu.elv", "/usr/share/elvish/lib/", "644"]
]

28
build.rs Normal file
View file

@ -0,0 +1,28 @@
use clap::{CommandFactory, command};
use clap_complete::{aot::Elvish, generate_to, shells::{Bash, Fish, Zsh}};
use std::env;
use std::io::Error;
include!("src/lib/cli.rs");
fn main() -> Result<(), Error> {
let outdir = match env::var_os("OUT_DIR") {
None => return Ok(()),
Some(outdir) => outdir,
};
let mut cmd = Cli::command();
let bash_path = generate_to(
Bash,
&mut cmd, // We need to specify what generator to use
"sdu", // We need to specify the bin name manually
&outdir, // We need to specify where to write to
)?;
let zsh_path = generate_to(Zsh, &mut cmd, "sdu", &outdir)?;
let fish_path = generate_to(Fish, &mut cmd, "sdu", &outdir)?;
let elvish_path = generate_to(Elvish, &mut cmd, "sdu", outdir)?;
println!("cargo:warning=completion files were generated: [ {bash_path:?}, {zsh_path:?}, {fish_path:?}, {elvish_path:?} ]");
Ok(())
}

6
debian/changelog vendored
View file

@ -1,3 +1,9 @@
sway-de-utils (0.1.7-1) unstable; urgency=medium
* implement shell completions for bash, fish, zsh
-- Penelope Gwen <support@pogmom.me> Sat, 24 Jan 2026 12:48:02 -0800
sway-de-utils (0.1.6-1) unstable; urgency=medium
* add retrieval of current workspace profile information for real this time

View file

@ -3,21 +3,8 @@ use clap::{ArgAction, Parser, Subcommand, ValueEnum};
#[derive(Parser)]
#[command(version, about, long_about = None)]
pub struct Cli {
/// Disable truncation of window titles
#[arg(short = 'T', long = "no-truncate-title", action = ArgAction::SetTrue)]
no_truncate_title: Option<bool>,
/// Enables monitoring for supported event types
#[arg(short = 'm', long = "monitor", action = ArgAction::SetTrue)]
monitor: Option<bool>,
/// Turn debugging information on
#[arg(short, long, action = ArgAction::Count)]
debug: u8,
#[command(subcommand)]
pub(crate) command: Commands,
// command: Commands,
}
#[derive(Subcommand)]
@ -49,17 +36,8 @@ pub enum Commands {
/// Lists global/profile shortcuts and optionally executes them
#[clap(alias = "scut")]
Shortcuts {
/// List shortcuts from global shortcut list rather than
// #[arg(short, long, action = ArgAction::SetTrue)]
// global: Option<bool>,
#[command(subcommand)]
shortcut_command: ShortcutCommand,
// /// Execute foud command
// #[arg(short, long, action = ArgAction::SetTrue)]
// execute: bool,
// /// Mode to print shortcut information
// #[command(subcommand)]
// mode: Option<ShortcutMode>
},
/// List or Execute Power/Session Commands
#[clap(alias = "pow")]
@ -210,3 +188,4 @@ pub enum ProfileGetCommand {
#[clap(alias = "i")]
Icon,
}

View file

@ -4,9 +4,7 @@ use log::debug;
use crate::{
config::{Profile, Programs},
lib::profile::active_profile,
lib::sway_ipc::{get_sway_connection, run_sway_command},
utils::SDUError,
lib::{profile::active_profile, get_sway_connection, run_sway_command, SDUError},
};
pub fn launch(

View file

@ -16,7 +16,7 @@ use shellexpand::tilde;
use xdg::BaseDirectories;
use crate::{
config::LockConf, lib::sway_ipc::get_sway_connection, utils::DirectoryType, utils::SDUError,
config::LockConf, lib::{sway_ipc::get_sway_connection, DirectoryType, SDUError},
};
#[derive(Serialize, Deserialize, Debug)]

View file

@ -10,6 +10,7 @@ mod sway;
mod sway_ipc;
mod windows;
mod workspaces;
mod utils;
pub use {
cli::{Cli, Commands},
@ -23,4 +24,5 @@ pub use {
sway_ipc::{get_sway_connection, run_sway_command},
windows::get_window_info,
workspaces::get_workspace_info,
utils::{setup_runtime_dir, get_xdg_dirs, SDUError, DirectoryType}
};

View file

@ -1,7 +1,7 @@
use {
crate::{
config::LockConf, lib::cli::PowerCommand, lib::lock_screen,
lib::sway_ipc::get_sway_connection, run_sway_command, utils::SDUError,
config::LockConf, lib::cli::PowerCommand,
lib::{lock_screen, get_sway_connection, run_sway_command, SDUError},
},
dialog::DialogBox,
log::debug,

View file

@ -5,12 +5,9 @@ use {
get_xdg_dirs,
lib::{
cli::{ProfileCommand, ProfileGetCommand, ProfileSwitchCommand},
get, get_sway_connection, run_sway_command, shortcuts_fn,
get, get_sway_connection, run_sway_command, shortcuts_fn, SDUError
},
setup_runtime_dir,
//lib::shortcuts::shortcuts_fn,
//lib::sway_ipc::{get_sway_connection, run_sway_command}
utils::SDUError,
},
log::{debug, error},
serde_json::json,

View file

@ -3,9 +3,11 @@ use serde_json::json;
use crate::{
config::ScriptConf,
lib::cli::{ShortcutCommand, ShortcutMode},
lib::sway_ipc::{get_sway_connection, run_sway_command},
utils::SDUError,
lib::{
cli::{ShortcutCommand, ShortcutMode},
sway_ipc::{get_sway_connection, run_sway_command},
SDUError,
},
};
fn print_shortcuts(mode: &ShortcutMode, shortcuts: Vec<ScriptConf>) -> String {

View file

@ -6,8 +6,8 @@ use {
get_scratchpad_info, get_sway_connection, get_window_info, get_workspace_info,
profile::profile_from_index,
sway_ipc::{self, get_sway_info},
SDUError
},
utils::SDUError,
},
log::debug,
serde_json::json,

View file

@ -3,14 +3,13 @@ use {
config::{Profile, WindowIcon},
lib::{
cli::SwayGetCommand, get_scratchpad_info, sway::focused_workspace_profile,
windows::get_window_info, workspaces::get_workspace_info,
},
utils::SDUError,
windows::get_window_info, workspaces::get_workspace_info, SDUError
}
},
log::debug,
serde_json::{Value, json},
std::time::Instant,
swayipc::{Connection, EventType},
swayipc::{Connection, EventType}
};
#[derive(serde::Serialize)]

View file

@ -1,19 +1,18 @@
#![warn(unused_crate_dependencies)]
//#![allow(clippy::style)]
mod config;
#[path = "lib/mod.rs"]
mod lib;
mod utils;
use {
crate::{
config::Config,
lib::{
Cli, Commands, launch, lock_screen, power_fn, profile_fn, run_sway_command,
shortcuts_fn, sway_fn,
Cli, Commands, get_xdg_dirs, launch, lock_screen, power_fn, profile_fn, setup_runtime_dir, shortcuts_fn, sway_fn
},
utils::{get_xdg_dirs, setup_runtime_dir},
},
clap::Parser,
log::{debug, error},
@ -21,7 +20,10 @@ use {
};
fn main() -> Result<(), ()> {
let _build_script = include_str!("../Cargo.toml");
let _build_script = include_str!("../Cargo.lock");
env_logger::init();
//Cli::command();
let cli = Cli::parse();
let config = if confy::get_configuration_file_path("sway-de-utils", "config")
.expect("Unable to determine config file location")