1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-16 22:31:03 +02:00

Merge pull request #683 from donovanglover/feat/man-pages-shell-completions

feat: add shell completions
This commit is contained in:
Jake Stanger 2024-12-29 00:24:54 +00:00 committed by GitHub
commit b2194d01c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 100 additions and 3 deletions

10
Cargo.lock generated
View file

@ -476,6 +476,15 @@ dependencies = [
"strsim 0.11.0",
]
[[package]]
name = "clap_complete"
version = "4.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b4be9c4c4b1f30b78d8a750e0822b6a6102d97e62061c583a6c1dea2dfb33ae"
dependencies = [
"clap",
]
[[package]]
name = "clap_derive"
version = "4.5.18"
@ -1722,6 +1731,7 @@ dependencies = [
"cfg-if",
"chrono",
"clap",
"clap_complete",
"color-eyre",
"ctrlc",
"dirs",

View file

@ -180,3 +180,9 @@ schemars = { version = "0.8.21", optional = true }
# -- PATCH --
# temp fix for tracing-appender/time
time = "0.3.37"
[build-dependencies]
clap = { version = "4.5.9", features = ["derive"] }
clap_complete = "4.5.2"
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.134"

53
build.rs Normal file
View file

@ -0,0 +1,53 @@
// Importing from Ironbar modules brings in lots of things not used by the build script
// we can just globally suppress those.
#![allow(unused, dead_code)]
#[path = "src/cli.rs"]
mod cli;
#[path = "src/error.rs"]
mod error;
#[path = "src/ipc"]
mod ipc {
#[path = "commands.rs"]
mod commands;
#[path = "responses.rs"]
mod responses;
pub use commands::Command;
pub use responses::Response;
}
use clap::Command;
use clap::CommandFactory;
use clap_complete::generate_to;
use clap_complete::Shell::{Bash, Fish, Zsh};
use cli::Args;
use std::fs;
use std::path::PathBuf;
const NAME: &str = "ironbar";
fn generate_shell_completions(mut cmd: Command) -> std::io::Result<()> {
const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
let comp_dir = PathBuf::from(MANIFEST_DIR).join("target/completions");
fs::create_dir_all(&comp_dir)?;
for shell in [Bash, Fish, Zsh] {
generate_to(shell, &mut cmd, NAME, &comp_dir)?;
}
Ok(())
}
fn main() -> std::io::Result<()> {
let mut cmd = Args::command();
cmd.set_bin_name(NAME);
generate_shell_completions(cmd)?;
Ok(())
}

View file

@ -117,6 +117,26 @@ cargo build --release --no-default-features \
| **Other** | |
| schema | Enables JSON schema support and the CLI `--print-schema` flag. |
## Shell completions
Compiling Ironbar will produce shell completions for bash, zsh and fish; these can be found in `target/completions`.
You can install these as follows:
Bash:
```shell
install -Dm644 completions/ironbar.bash /usr/share/bash-completion/completions/ironbar
```
Zsh:
```shell
install -Dm644 completions/_ironbar /usr/share/zsh/site-functions/_ironbar
```
Fish:
```shell
install -Dm644 completions/ironbar.fish /usr/share/fish/vendor_completions.d/ironbar.fish
```
## Speeding up compiling

View file

@ -20,6 +20,7 @@
luajit,
luajitPackages,
pkg-config,
installShellFiles,
adwaita-icon-theme,
hicolor-icon-theme,
rustPlatform,
@ -45,6 +46,7 @@
pkg-config
wrapGAppsHook
gobject-introspection
installShellFiles
];
buildInputs = [
@ -89,6 +91,13 @@
)
'';
postInstall = ''
installShellCompletion --cmd ironbar \
--bash target/completions/ironbar.bash \
--fish target/completions/ironbar.fish \
--zsh target/completions/_ironbar
'';
passthru = {
updateScript = gnome.updateScript {
packageName = pname;

View file

@ -1,6 +1,5 @@
use crate::error::ExitCode;
use crate::ipc::commands::Command;
use crate::ipc::responses::Response;
use crate::ipc::{Command, Response};
use clap::{Parser, ValueEnum};
use serde::{Deserialize, Serialize};
use std::process::exit;