Skip to content

Commit

Permalink
Support generating shell completions (atuinsh#235)
Browse files Browse the repository at this point in the history
* Add gen-completions subcommand for generating shell completions

* Update documentation about generating shell completions

* Include the shell completions in release tarball
  • Loading branch information
orhun authored Dec 10, 2021
1 parent 28f78ba commit 0abd063
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,19 @@ 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"
# 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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions docs/shell-completions.md
Original file line number Diff line number Diff line change
@@ -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).
19 changes: 18 additions & 1 deletion src/command/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;

use eyre::{Result, WrapErr};
use structopt::clap::Shell;
use structopt::StructOpt;

use atuin_client::database::Sqlite;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(())
}
}
}
}

0 comments on commit 0abd063

Please sign in to comment.