Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat: add shell completions (#1213)

hunny warisu1a9291f1d1d0
diff --git a/content/docs/pages/docs/cli-reference.mdx b/content/docs/pages/docs/cli-reference.mdx
index 7a54caaa8..b216da205 100644
--- a/content/docs/pages/docs/cli-reference.mdx
+++ b/content/docs/pages/docs/cli-reference.mdx
@@ -316,4 +316,59 @@ note: if you don't provide a metadata override file, screenpipe will automatical
screenpipe migrate
```
+
+### Shell Completions
+
+The `screenpipe` CLI supports generating shell completions for popular shells. Follow the steps below to enable autocompletion for your shell:
+
+#### Bash
+1. Add the following to your `.bashrc` profile:
+ ```bash
+ eval "$(screenpipe completions bash)"
+ ```
+2. Reload your profile:
+ ```bash
+ source ~/.bashrc
+ ```
+
+#### Zsh
+1. Add the following to your `.zshrc` profile:
+ ```bash
+ eval "$(screenpipe completions zsh)"
+ ```
+2. Reload your profile:
+ ```bash
+ source ~/.zshrc
+ ```
+`
+#### Fish
+1. Create `~/.config/fish/conf.d/screenpipe.fish` and add this line to it:
+ ```fish
+ screenpipe completions fish | source
+ ```
+
+#### PowerShell
+1. Add the following to the end of your profile file:
+ ```powershell
+ screenpipe completions powershell | Out-String | Invoke-Expression
+ ```
+
+- For macOS/Linux, the profile is located at `~/.config/powershell/Microsoft.PowerShell_profile.ps1`
+- For Windows location is either:
+ - `%userprofile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1` Powershell 5
+ - `%userprofile%\Documents\PowerShell\Microsoft.PowerShell_profile.ps1` Powershell 6+
+- To create the profile file you can run this in PowerShell:
+ ```powershell
+ if (-not (Test-Path $profile)) { New-Item $profile -Force }
+ ```
+- To edit your profile run this in PowerShell:
+ ```powershell
+ Invoke-Item $profile
+ ```
+2. Reload your profile:
+ ```powershell
+ . $PROFILE
+ ```
+
+
</MotionDiv>
diff --git a/screenpipe-server/Cargo.toml b/screenpipe-server/Cargo.toml
index 4b3641594..08aa39114 100644
--- a/screenpipe-server/Cargo.toml
+++ b/screenpipe-server/Cargo.toml
@@ -69,6 +69,9 @@ sysinfo = "0.29.0"
# Color
colored = "2.0"
+# Completions
+clap_complete = "4.2"
+
# Plugins
tower = { version = "0.5", features = ["util"] }
futures = "0.3.17"
diff --git a/screenpipe-server/src/bin/screenpipe-server.rs b/screenpipe-server/src/bin/screenpipe-server.rs
index 5db1d4e5c..311c1c9de 100644
--- a/screenpipe-server/src/bin/screenpipe-server.rs
+++ b/screenpipe-server/src/bin/screenpipe-server.rs
@@ -226,6 +226,10 @@ async fn main() -> anyhow::Result<()> {
let pipe_manager = Arc::new(PipeManager::new(local_data_dir_clone.clone()));
+ if let Some(Command::Completions { shell }) = &cli.command {
+ cli.handle_completions(shell.clone())?;
+ return Ok(());
+ }
if let Some(command) = cli.command {
match command {
Command::Pipe { subcommand } => {
@@ -431,6 +435,7 @@ async fn main() -> anyhow::Result<()> {
handle_doctor_command(output, fix).await?;
return Ok(());
}
+ Command::Completions { .. } => todo!(),
}
}
diff --git a/screenpipe-server/src/cli.rs b/screenpipe-server/src/cli.rs
index 1c2682240..af8735d61 100644
--- a/screenpipe-server/src/cli.rs
+++ b/screenpipe-server/src/cli.rs
@@ -1,9 +1,11 @@
use std::path::PathBuf;
-use clap::{Parser, Subcommand};
+use clap::{CommandFactory, Parser, Subcommand, ValueHint};
+use clap_complete::{generate, Shell};
use screenpipe_audio::{vad_engine::VadSensitivity, AudioTranscriptionEngine as CoreAudioTranscriptionEngine};
use screenpipe_vision::{custom_ocr::CustomOcrConfig, utils::OcrEngine as CoreOcrEngine};
use clap::ValueEnum;
+use anyhow::Result;
use screenpipe_audio::vad_engine::VadEngineEnum;
use screenpipe_core::Language;
@@ -151,7 +153,7 @@ pub struct Cli {
pub list_audio_devices: bool,
/// Data directory. Default to $HOME/.screenpipe
- #[arg(long)]
+ #[arg(long, value_hint = ValueHint::DirPath)]
pub data_dir: Option<String>,
/// Enable debug logging for screenpipe modules
@@ -287,6 +289,12 @@ impl Cli {
}
Ok(unique_langs.into_iter().collect())
}
+
+ pub fn handle_completions(&self, shell: Shell) -> anyhow::Result<()> {
+ let mut cmd = Self::command();
+ generate(shell, &mut cmd, "screenpipe", &mut std::io::stdout());
+ Ok(())
+ }
}
#[derive(Subcommand)]
@@ -311,7 +319,7 @@ pub enum Command {
/// Path to folder containing video files
path: String,
/// Data directory. Default to $HOME/.screenpipe
- #[arg(long)]
+ #[arg(long, value_hint = ValueHint::DirPath)]
data_dir: Option<String>,
/// Output format
#[arg(short = 'o', long, value_enum, default_value_t = OutputFormat::Text)]
@@ -323,7 +331,7 @@ pub enum Command {
#[arg(short = 'o', long, value_enum)]
ocr_engine: Option<CliOcrEngine>,
/// Path to JSON file containing metadata overrides
- #[arg(long)]
+ #[arg(long, value_hint = ValueHint::FilePath)]
metadata_override: Option<PathBuf>,
/// Copy videos to screenpipe data directory
#[arg(long, default_value_t = true)]
@@ -340,6 +348,12 @@ pub enum Command {
/// Enable beta features
#[arg(long, default_value_t = false)]
enable_beta: bool,
+ },
+ /// Generate shell completions
+ Completions {
+ /// The shell to generate completions for
+ #[arg(value_enum)]
+ shell: Shell,
},
/// Run database migrations
Migrate,