Add auto-generated completions for Fig

This commit is contained in:
Ajeet D'Souza 2021-10-21 03:53:20 +05:30
parent 6bf966f18d
commit 7ec9ad6a27
5 changed files with 238 additions and 0 deletions

View File

@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Added
- Auto-generated completions for [Fig](https://fig.io/).
### Fixed
- Fix compile errors due to broken `clap` dependency.

11
Cargo.lock generated
View File

@ -179,6 +179,16 @@ dependencies = [
"clap",
]
[[package]]
name = "clap_generate_fig"
version = "3.0.0-beta.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3482836f06a77604c543ffbf86b0b9b814e5413cec432d75fea9db7eb9bf26d"
dependencies = [
"clap",
"clap_generate",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.5"
@ -856,6 +866,7 @@ dependencies = [
"bincode",
"clap",
"clap_generate",
"clap_generate_fig",
"dirs-next",
"dunce",
"glob",

View File

@ -36,6 +36,7 @@ rand = { version = "0.8.4", features = [
[build-dependencies]
clap = "=3.0.0-beta.5"
clap_generate = "=3.0.0-beta.5"
clap_generate_fig = "=3.0.0-beta.5"
[dev-dependencies]
assert_cmd = "2.0.0"

View File

@ -39,6 +39,7 @@ fn generate_completions() -> io::Result<()> {
use clap::IntoApp;
use clap_generate::generate_to;
use clap_generate::generators::{Bash, Elvish, Fish, PowerShell, Zsh};
use clap_generate_fig::Fig;
let app = &mut App::into_app();
let bin_name = env!("CARGO_PKG_NAME");
@ -46,6 +47,7 @@ fn generate_completions() -> io::Result<()> {
generate_to(Bash, app, bin_name, out_dir)?;
generate_to(Elvish, app, bin_name, out_dir)?;
generate_to(Fig, app, bin_name, out_dir)?;
generate_to(Fish, app, bin_name, out_dir)?;
generate_to(PowerShell, app, bin_name, out_dir)?;
generate_to(Zsh, app, bin_name, out_dir)?;

View File

@ -0,0 +1,220 @@
const completion: Fig.Spec = {
name: "zoxide",
description: "A smarter cd command for your terminal",
subcommands: [
{
name: "add",
description: "Add a new directory or increment its rank",
options: [
{
name: ["-h", "--help"],
description: "Print help information",
},
{
name: ["-V", "--version"],
description: "Print version information",
},
],
args: {
name: "paths",
isVariadic: true,
template: "folders",
},
},
{
name: "import",
description: "Import entries from another application",
options: [
{
name: "--from",
description: "Application to import from",
args: {
name: "from",
suggestions: [
{
name: "autojump",
},
{
name: "z",
},
]
},
},
{
name: "--merge",
description: "Merge into existing database",
},
{
name: ["-h", "--help"],
description: "Print help information",
},
{
name: ["-V", "--version"],
description: "Print version information",
},
],
args: {
name: "path",
template: "filepaths",
},
},
{
name: "init",
description: "Generate shell configuration",
options: [
{
name: "--cmd",
description: "Renames the 'z' command and corresponding aliases",
args: {
name: "cmd",
isOptional: true,
},
},
{
name: "--hook",
description: "Chooses event upon which an entry is added to the database",
args: {
name: "hook",
isOptional: true,
suggestions: [
{
name: "none",
},
{
name: "prompt",
},
{
name: "pwd",
},
]
},
},
{
name: "--no-aliases",
description: "Prevents zoxide from defining any commands",
},
{
name: ["-h", "--help"],
description: "Print help information",
},
{
name: ["-V", "--version"],
description: "Print version information",
},
],
args: {
name: "shell",
suggestions: [
{
name: "bash",
},
{
name: "elvish",
},
{
name: "fish",
},
{
name: "nushell",
},
{
name: "posix",
},
{
name: "powershell",
},
{
name: "xonsh",
},
{
name: "zsh",
},
]
},
},
{
name: "query",
description: "Search for a directory in the database",
options: [
{
name: "--exclude",
description: "Exclude a path from results",
args: {
name: "exclude",
isOptional: true,
template: "folders",
},
},
{
name: "--all",
description: "Show deleted directories",
},
{
name: ["-i", "--interactive"],
description: "Use interactive selection",
},
{
name: ["-l", "--list"],
description: "List all matching directories",
},
{
name: ["-s", "--score"],
description: "Print score with results",
},
{
name: ["-h", "--help"],
description: "Print help information",
},
{
name: ["-V", "--version"],
description: "Print version information",
},
],
args: {
name: "keywords",
isVariadic: true,
isOptional: true,
},
},
{
name: "remove",
description: "Remove a directory from the database",
options: [
{
name: ["-i", "--interactive"],
args: {
name: "interactive",
isVariadic: true,
isOptional: true,
},
},
{
name: ["-h", "--help"],
description: "Print help information",
},
{
name: ["-V", "--version"],
description: "Print version information",
},
],
args: {
name: "paths",
isVariadic: true,
isOptional: true,
template: "folders",
},
},
],
options: [
{
name: ["-h", "--help"],
description: "Print help information",
},
{
name: ["-V", "--version"],
description: "Print version information",
},
],
};
export default completion;