Skip to content

Commit b2194d0

Browse files
authored
Merge pull request #683 from donovanglover/feat/man-pages-shell-completions
feat: add shell completions
2 parents df55cdf + 4381fd5 commit b2194d0

File tree

6 files changed

+100
-3
lines changed

6 files changed

+100
-3
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,10 @@ schemars = { version = "0.8.21", optional = true }
179179

180180
# -- PATCH --
181181
# temp fix for tracing-appender/time
182-
time = "0.3.37"
182+
time = "0.3.37"
183+
184+
[build-dependencies]
185+
clap = { version = "4.5.9", features = ["derive"] }
186+
clap_complete = "4.5.2"
187+
serde = { version = "1.0.204", features = ["derive"] }
188+
serde_json = "1.0.134"

build.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Importing from Ironbar modules brings in lots of things not used by the build script
2+
// we can just globally suppress those.
3+
#![allow(unused, dead_code)]
4+
5+
#[path = "src/cli.rs"]
6+
mod cli;
7+
8+
#[path = "src/error.rs"]
9+
mod error;
10+
11+
#[path = "src/ipc"]
12+
mod ipc {
13+
#[path = "commands.rs"]
14+
mod commands;
15+
16+
#[path = "responses.rs"]
17+
mod responses;
18+
19+
pub use commands::Command;
20+
pub use responses::Response;
21+
}
22+
23+
use clap::Command;
24+
use clap::CommandFactory;
25+
use clap_complete::generate_to;
26+
use clap_complete::Shell::{Bash, Fish, Zsh};
27+
use cli::Args;
28+
use std::fs;
29+
use std::path::PathBuf;
30+
31+
const NAME: &str = "ironbar";
32+
33+
fn generate_shell_completions(mut cmd: Command) -> std::io::Result<()> {
34+
const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
35+
let comp_dir = PathBuf::from(MANIFEST_DIR).join("target/completions");
36+
37+
fs::create_dir_all(&comp_dir)?;
38+
39+
for shell in [Bash, Fish, Zsh] {
40+
generate_to(shell, &mut cmd, NAME, &comp_dir)?;
41+
}
42+
43+
Ok(())
44+
}
45+
46+
fn main() -> std::io::Result<()> {
47+
let mut cmd = Args::command();
48+
cmd.set_bin_name(NAME);
49+
50+
generate_shell_completions(cmd)?;
51+
52+
Ok(())
53+
}

docs/Compiling.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@ cargo build --release --no-default-features \
117117
| **Other** | |
118118
| schema | Enables JSON schema support and the CLI `--print-schema` flag. |
119119

120+
## Shell completions
121+
122+
Compiling Ironbar will produce shell completions for bash, zsh and fish; these can be found in `target/completions`.
123+
124+
You can install these as follows:
125+
126+
Bash:
127+
```shell
128+
install -Dm644 completions/ironbar.bash /usr/share/bash-completion/completions/ironbar
129+
```
130+
131+
Zsh:
132+
```shell
133+
install -Dm644 completions/_ironbar /usr/share/zsh/site-functions/_ironbar
134+
```
135+
136+
Fish:
137+
```shell
138+
install -Dm644 completions/ironbar.fish /usr/share/fish/vendor_completions.d/ironbar.fish
139+
```
120140

121141
## Speeding up compiling
122142

nix/default.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
luajit,
2121
luajitPackages,
2222
pkg-config,
23+
installShellFiles,
2324
adwaita-icon-theme,
2425
hicolor-icon-theme,
2526
rustPlatform,
@@ -45,6 +46,7 @@
4546
pkg-config
4647
wrapGAppsHook
4748
gobject-introspection
49+
installShellFiles
4850
];
4951

5052
buildInputs = [
@@ -89,6 +91,13 @@
8991
)
9092
'';
9193

94+
postInstall = ''
95+
installShellCompletion --cmd ironbar \
96+
--bash target/completions/ironbar.bash \
97+
--fish target/completions/ironbar.fish \
98+
--zsh target/completions/_ironbar
99+
'';
100+
92101
passthru = {
93102
updateScript = gnome.updateScript {
94103
packageName = pname;

src/cli.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::error::ExitCode;
2-
use crate::ipc::commands::Command;
3-
use crate::ipc::responses::Response;
2+
use crate::ipc::{Command, Response};
43
use clap::{Parser, ValueEnum};
54
use serde::{Deserialize, Serialize};
65
use std::process::exit;

0 commit comments

Comments
 (0)