mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-16 22:31:03 +02:00
feat: add shell completions
Auto-generated with clap.
This commit is contained in:
parent
df55cdfa9f
commit
4381fd505d
6 changed files with 100 additions and 3 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -476,6 +476,15 @@ dependencies = [
|
||||||
"strsim 0.11.0",
|
"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]]
|
[[package]]
|
||||||
name = "clap_derive"
|
name = "clap_derive"
|
||||||
version = "4.5.18"
|
version = "4.5.18"
|
||||||
|
@ -1722,6 +1731,7 @@ dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
|
"clap_complete",
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
"ctrlc",
|
"ctrlc",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
|
|
@ -179,4 +179,10 @@ schemars = { version = "0.8.21", optional = true }
|
||||||
|
|
||||||
# -- PATCH --
|
# -- PATCH --
|
||||||
# temp fix for tracing-appender/time
|
# temp fix for tracing-appender/time
|
||||||
time = "0.3.37"
|
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
53
build.rs
Normal 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(())
|
||||||
|
}
|
|
@ -117,6 +117,26 @@ cargo build --release --no-default-features \
|
||||||
| **Other** | |
|
| **Other** | |
|
||||||
| schema | Enables JSON schema support and the CLI `--print-schema` flag. |
|
| 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
|
## Speeding up compiling
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
luajit,
|
luajit,
|
||||||
luajitPackages,
|
luajitPackages,
|
||||||
pkg-config,
|
pkg-config,
|
||||||
|
installShellFiles,
|
||||||
adwaita-icon-theme,
|
adwaita-icon-theme,
|
||||||
hicolor-icon-theme,
|
hicolor-icon-theme,
|
||||||
rustPlatform,
|
rustPlatform,
|
||||||
|
@ -45,6 +46,7 @@
|
||||||
pkg-config
|
pkg-config
|
||||||
wrapGAppsHook
|
wrapGAppsHook
|
||||||
gobject-introspection
|
gobject-introspection
|
||||||
|
installShellFiles
|
||||||
];
|
];
|
||||||
|
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
|
@ -89,6 +91,13 @@
|
||||||
)
|
)
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
postInstall = ''
|
||||||
|
installShellCompletion --cmd ironbar \
|
||||||
|
--bash target/completions/ironbar.bash \
|
||||||
|
--fish target/completions/ironbar.fish \
|
||||||
|
--zsh target/completions/_ironbar
|
||||||
|
'';
|
||||||
|
|
||||||
passthru = {
|
passthru = {
|
||||||
updateScript = gnome.updateScript {
|
updateScript = gnome.updateScript {
|
||||||
packageName = pname;
|
packageName = pname;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::error::ExitCode;
|
use crate::error::ExitCode;
|
||||||
use crate::ipc::commands::Command;
|
use crate::ipc::{Command, Response};
|
||||||
use crate::ipc::responses::Response;
|
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue