aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock11
-rw-r--r--Cargo.toml1
-rw-r--r--flake.nix1
-rw-r--r--src/cli.rs27
-rw-r--r--src/main.rs24
5 files changed, 61 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 081f16dc..00be0ae2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -644,6 +644,16 @@ dependencies = [
]
[[package]]
+name = "clap_complete_nushell"
+version = "4.5.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0a0c951694691e65bf9d421d597d68416c22de9632e884c28412cb8cd8b73dce"
+dependencies = [
+ "clap",
+ "clap_complete",
+]
+
+[[package]]
name = "clap_derive"
version = "4.5.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2267,6 +2277,7 @@ dependencies = [
"calloop-wayland-source 0.4.0",
"clap",
"clap_complete",
+ "clap_complete_nushell",
"directories",
"drm-ffi",
"fastrand",
diff --git a/Cargo.toml b/Cargo.toml
index 5a35b6da..6f454e7f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -60,6 +60,7 @@ bytemuck = { version = "1.23.1", features = ["derive"] }
calloop = { version = "0.14.2", features = ["executor", "futures-io"] }
clap = { workspace = true, features = ["string"] }
clap_complete = "4.5.55"
+clap_complete_nushell = "4.5.8"
directories = "6.0.0"
drm-ffi = "0.9.0"
fastrand = "2.3.0"
diff --git a/flake.nix b/flake.nix
index c19cca05..f78024dc 100644
--- a/flake.nix
+++ b/flake.nix
@@ -122,6 +122,7 @@
installShellCompletion --cmd niri \
--bash <($out/bin/niri completions bash) \
--fish <($out/bin/niri completions fish) \
+ --nushell <($out/bin/niri completions nushell) \
--zsh <($out/bin/niri completions zsh)
install -Dm644 resources/niri.desktop -t $out/share/wayland-sessions
diff --git a/src/cli.rs b/src/cli.rs
index cb3cc0ab..933712c2 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -56,7 +56,7 @@ pub enum Sub {
/// Cause a panic to check if the backtraces are good.
Panic,
/// Generate shell completions.
- Completions { shell: Shell },
+ Completions { shell: CompletionShell },
}
#[derive(Subcommand)]
@@ -108,3 +108,28 @@ pub enum Msg {
/// Print the overview state.
OverviewState,
}
+
+#[derive(Clone, Debug, clap::ValueEnum)]
+pub enum CompletionShell {
+ Bash,
+ Elvish,
+ Fish,
+ PowerShell,
+ Zsh,
+ Nushell,
+}
+
+impl TryFrom<CompletionShell> for Shell {
+ type Error = &'static str;
+
+ fn try_from(shell: CompletionShell) -> Result<Self, Self::Error> {
+ match shell {
+ CompletionShell::Bash => Ok(Shell::Bash),
+ CompletionShell::Elvish => Ok(Shell::Elvish),
+ CompletionShell::Fish => Ok(Shell::Fish),
+ CompletionShell::PowerShell => Ok(Shell::PowerShell),
+ CompletionShell::Zsh => Ok(Shell::Zsh),
+ CompletionShell::Nushell => Err("Nushell should be handled separately"),
+ }
+ }
+}
diff --git a/src/main.rs b/src/main.rs
index 0eeb57bf..73d60bb4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,8 +10,10 @@ use std::process::Command;
use std::{env, mem};
use clap::{CommandFactory, Parser};
+use clap_complete::Shell;
+use clap_complete_nushell::Nushell;
use directories::ProjectDirs;
-use niri::cli::{Cli, Sub};
+use niri::cli::{Cli, CompletionShell, Sub};
#[cfg(feature = "dbus")]
use niri::dbus;
use niri::ipc::client::handle_msg;
@@ -108,7 +110,25 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
Sub::Panic => cause_panic(),
Sub::Completions { shell } => {
- clap_complete::generate(shell, &mut Cli::command(), "niri", &mut io::stdout());
+ match shell {
+ CompletionShell::Nushell => {
+ clap_complete::generate(
+ Nushell,
+ &mut Cli::command(),
+ "niri",
+ &mut io::stdout(),
+ );
+ }
+ other => {
+ let generator = Shell::try_from(other).unwrap();
+ clap_complete::generate(
+ generator,
+ &mut Cli::command(),
+ "niri",
+ &mut io::stdout(),
+ );
+ }
+ }
return Ok(());
}
}