summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOrhun Parmaksız <orhunparmaksiz@gmail.com>2021-12-11 02:59:39 +0300
committerGitHub <noreply@github.com>2021-12-10 23:59:39 +0000
commit0abd063e018ecb8851c3a816aa941dd04d594c9e (patch)
treee61f6858727989bf7d848d7dab76632e6657b222
parent28f78ba4e1874f6ab2eee2b833fb1b12d50e3ebe (diff)
Support generating shell completions (#235)
* Add gen-completions subcommand for generating shell completions * Update documentation about generating shell completions * Include the shell completions in release tarball
-rw-r--r--.github/workflows/release.yaml7
-rw-r--r--README.md1
-rw-r--r--docs/shell-completions.md19
-rw-r--r--src/command/mod.rs19
4 files changed, 44 insertions, 2 deletions
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index 8784435c..7298ce2e 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -116,7 +116,7 @@ jobs:
PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package"
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/"
mkdir -p "${ARCHIVE_DIR}"
- mkdir -p "${ARCHIVE_DIR}/autocomplete"
+ mkdir -p "${ARCHIVE_DIR}/completions"
# Binary
cp "${{ steps.strip.outputs.BIN_PATH }}" "$ARCHIVE_DIR"
@@ -124,6 +124,11 @@ jobs:
# README, LICENSE and CHANGELOG files
cp "README.md" "LICENSE" "$ARCHIVE_DIR"
+ # Shell completions
+ for sh in 'bash' 'fish' 'zsh'; do
+ "${{ steps.strip.outputs.BIN_PATH }}" gen-completions -s $sh -o "${ARCHIVE_DIR}/completions"
+ done
+
# base compressed package
pushd "${PKG_STAGING}/" >/dev/null
case ${{ matrix.job.target }} in
diff --git a/README.md b/README.md
index 7abb664f..5f3fe338 100644
--- a/README.md
+++ b/README.md
@@ -59,6 +59,7 @@ I wanted to. And I **really** don't want to.
- [History stats](docs/stats.md)
- [Running your own server](docs/server.md)
- [Key binding](docs/key-binding.md)
+- [Shell completions](docs/shell-completions.md)
## Supported Shells
diff --git a/docs/shell-completions.md b/docs/shell-completions.md
new file mode 100644
index 00000000..4adf82b0
--- /dev/null
+++ b/docs/shell-completions.md
@@ -0,0 +1,19 @@
+# `atuin gen-completions`
+
+[Shell completions](https://en.wikipedia.org/wiki/Command-line_completion) for Atuin can be generated by specifying the output directory and desired shell via `gen-completions` subcommand.
+
+```
+$ atuin gen-completions --shell bash --out-dir $HOME
+
+Shell completion for BASH is generated in "/home/user"
+```
+
+Possible values for the `--shell` argument are the following:
+
+- `bash`
+- `fish`
+- `zsh`
+- `powershell`
+- `elvish`
+
+Also, see the [supported shells](./../README.md#supported-shells).
diff --git a/src/command/mod.rs b/src/command/mod.rs
index dc1f01fb..d82ad13b 100644
--- a/src/command/mod.rs
+++ b/src/command/mod.rs
@@ -1,6 +1,7 @@
use std::path::PathBuf;
use eyre::{Result, WrapErr};
+use structopt::clap::Shell;
use structopt::StructOpt;
use atuin_client::database::Sqlite;
@@ -92,6 +93,15 @@ pub enum AtuinCmd {
#[structopt(about = "print the encryption key for transfer to another machine")]
Key,
+
+ #[structopt(about = "generate shell completions")]
+ GenCompletions {
+ #[structopt(long, short, help = "set the shell for generating completions")]
+ shell: Shell,
+
+ #[structopt(long, short, help = "set the output directory")]
+ out_dir: String,
+ },
}
impl AtuinCmd {
@@ -157,11 +167,18 @@ impl AtuinCmd {
println!("{}", encode);
Ok(())
}
-
Self::Uuid => {
println!("{}", uuid_v4());
Ok(())
}
+ Self::GenCompletions { shell, out_dir } => {
+ AtuinCmd::clap().gen_completions(env!("CARGO_PKG_NAME"), shell, &out_dir);
+ println!(
+ "Shell completion for {} is generated in {:?}",
+ shell, out_dir
+ );
+ Ok(())
+ }
}
}
}