2022-09-16 16:54:46 +00:00
|
|
|
#![allow(clippy::module_inception)]
|
|
|
|
|
2022-09-06 22:49:45 +00:00
|
|
|
use std::path::PathBuf;
|
2021-09-13 08:01:58 +00:00
|
|
|
|
2022-10-29 14:16:10 +00:00
|
|
|
use clap::{Parser, ValueEnum, ValueHint};
|
2022-09-16 16:54:46 +00:00
|
|
|
|
2021-05-03 21:03:23 +00:00
|
|
|
const ENV_HELP: &str = "ENVIRONMENT VARIABLES:
|
|
|
|
_ZO_DATA_DIR Path for zoxide data files
|
2021-10-28 06:53:14 +00:00
|
|
|
_ZO_ECHO Print the matched directory before navigating to it when set to 1
|
2021-05-03 21:03:23 +00:00
|
|
|
_ZO_EXCLUDE_DIRS List of directory globs to be excluded
|
|
|
|
_ZO_FZF_OPTS Custom flags to pass to fzf
|
|
|
|
_ZO_MAXAGE Maximum total age after which entries start getting deleted
|
|
|
|
_ZO_RESOLVE_SYMLINKS Resolve symlinks when storing paths";
|
|
|
|
|
2021-10-20 18:31:06 +00:00
|
|
|
#[derive(Debug, Parser)]
|
2021-05-03 21:03:23 +00:00
|
|
|
#[clap(
|
|
|
|
bin_name = env!("CARGO_PKG_NAME"),
|
|
|
|
about,
|
|
|
|
author,
|
|
|
|
after_help = ENV_HELP,
|
2022-02-16 22:46:45 +00:00
|
|
|
disable_help_subcommand = true,
|
|
|
|
propagate_version = true,
|
2021-05-03 21:12:43 +00:00
|
|
|
version = option_env!("ZOXIDE_VERSION").unwrap_or_default()
|
2021-05-03 21:03:23 +00:00
|
|
|
)]
|
2022-02-16 22:46:45 +00:00
|
|
|
pub enum Cmd {
|
2021-05-03 21:03:23 +00:00
|
|
|
Add(Add),
|
|
|
|
Import(Import),
|
|
|
|
Init(Init),
|
|
|
|
Query(Query),
|
|
|
|
Remove(Remove),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add a new directory or increment its rank
|
2021-10-20 18:31:06 +00:00
|
|
|
#[derive(Debug, Parser)]
|
2021-05-03 21:03:23 +00:00
|
|
|
pub struct Add {
|
2022-10-29 14:16:10 +00:00
|
|
|
#[clap(num_args = 1.., required = true, value_hint = ValueHint::DirPath)]
|
2021-07-29 03:50:40 +00:00
|
|
|
pub paths: Vec<PathBuf>,
|
2021-05-03 21:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Import entries from another application
|
2021-10-20 18:31:06 +00:00
|
|
|
#[derive(Debug, Parser)]
|
2021-05-03 21:03:23 +00:00
|
|
|
pub struct Import {
|
2021-05-19 21:24:06 +00:00
|
|
|
#[clap(value_hint = ValueHint::FilePath)]
|
2021-05-03 21:03:23 +00:00
|
|
|
pub path: PathBuf,
|
|
|
|
|
|
|
|
/// Application to import from
|
2022-10-29 14:16:10 +00:00
|
|
|
#[clap(value_enum, long)]
|
2021-05-03 21:12:43 +00:00
|
|
|
pub from: ImportFrom,
|
2021-05-03 21:03:23 +00:00
|
|
|
|
|
|
|
/// Merge into existing database
|
|
|
|
#[clap(long)]
|
|
|
|
pub merge: bool,
|
|
|
|
}
|
|
|
|
|
2022-10-29 14:16:10 +00:00
|
|
|
#[derive(ValueEnum, Clone, Debug)]
|
2021-05-03 21:12:43 +00:00
|
|
|
pub enum ImportFrom {
|
2021-05-03 21:03:23 +00:00
|
|
|
Autojump,
|
|
|
|
Z,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Generate shell configuration
|
2021-10-20 18:31:06 +00:00
|
|
|
#[derive(Debug, Parser)]
|
2021-05-03 21:03:23 +00:00
|
|
|
pub struct Init {
|
2022-10-29 14:16:10 +00:00
|
|
|
#[clap(value_enum)]
|
2021-05-03 21:12:43 +00:00
|
|
|
pub shell: InitShell,
|
2021-05-03 21:03:23 +00:00
|
|
|
|
2022-04-10 22:11:51 +00:00
|
|
|
/// Prevents zoxide from defining the `z` and `zi` commands
|
|
|
|
#[clap(long, alias = "no-aliases")]
|
|
|
|
pub no_cmd: bool,
|
2021-05-03 21:03:23 +00:00
|
|
|
|
2022-04-10 22:11:51 +00:00
|
|
|
/// Changes the prefix of the `z` and `zi` commands
|
2021-05-03 21:03:23 +00:00
|
|
|
#[clap(long, default_value = "z")]
|
|
|
|
pub cmd: String,
|
|
|
|
|
2022-04-10 22:11:51 +00:00
|
|
|
/// Changes how often zoxide increments a directory's score
|
2022-10-29 14:16:10 +00:00
|
|
|
#[clap(value_enum, long, default_value = "pwd")]
|
2021-05-03 21:12:43 +00:00
|
|
|
pub hook: InitHook,
|
|
|
|
}
|
|
|
|
|
2022-10-29 14:16:10 +00:00
|
|
|
#[derive(ValueEnum, Clone, Copy, Debug, Eq, PartialEq)]
|
2021-05-03 21:12:43 +00:00
|
|
|
pub enum InitHook {
|
|
|
|
None,
|
|
|
|
Prompt,
|
|
|
|
Pwd,
|
2021-05-03 21:03:23 +00:00
|
|
|
}
|
|
|
|
|
2022-10-29 14:16:10 +00:00
|
|
|
#[derive(ValueEnum, Clone, Debug)]
|
2021-05-03 21:12:43 +00:00
|
|
|
pub enum InitShell {
|
2021-05-03 21:03:23 +00:00
|
|
|
Bash,
|
|
|
|
Elvish,
|
|
|
|
Fish,
|
|
|
|
Nushell,
|
|
|
|
Posix,
|
|
|
|
Powershell,
|
|
|
|
Xonsh,
|
|
|
|
Zsh,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Search for a directory in the database
|
2021-10-20 18:31:06 +00:00
|
|
|
#[derive(Debug, Parser)]
|
2021-05-03 21:03:23 +00:00
|
|
|
pub struct Query {
|
|
|
|
pub keywords: Vec<String>,
|
|
|
|
|
2021-05-08 03:05:34 +00:00
|
|
|
/// Show deleted directories
|
|
|
|
#[clap(long)]
|
|
|
|
pub all: bool,
|
|
|
|
|
2021-05-03 21:03:23 +00:00
|
|
|
/// Use interactive selection
|
|
|
|
#[clap(long, short, conflicts_with = "list")]
|
|
|
|
pub interactive: bool,
|
|
|
|
|
|
|
|
/// List all matching directories
|
|
|
|
#[clap(long, short, conflicts_with = "interactive")]
|
|
|
|
pub list: bool,
|
|
|
|
|
|
|
|
/// Print score with results
|
2022-04-13 11:33:06 +00:00
|
|
|
#[clap(long, short)]
|
2021-05-03 21:03:23 +00:00
|
|
|
pub score: bool,
|
|
|
|
|
|
|
|
/// Exclude a path from results
|
2021-05-19 21:24:06 +00:00
|
|
|
#[clap(long, value_hint = ValueHint::DirPath, value_name = "path")]
|
2021-05-03 21:03:23 +00:00
|
|
|
pub exclude: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Remove a directory from the database
|
2021-10-20 18:31:06 +00:00
|
|
|
#[derive(Debug, Parser)]
|
2021-05-03 21:03:23 +00:00
|
|
|
pub struct Remove {
|
2021-12-24 12:19:36 +00:00
|
|
|
/// Use interactive selection
|
|
|
|
#[clap(long, short)]
|
|
|
|
pub interactive: bool,
|
|
|
|
#[clap(value_hint = ValueHint::DirPath)]
|
2021-07-29 03:50:40 +00:00
|
|
|
pub paths: Vec<String>,
|
2021-05-03 21:03:23 +00:00
|
|
|
}
|