-
Notifications
You must be signed in to change notification settings - Fork 619
/
Copy pathcmd.rs
141 lines (117 loc) · 3.39 KB
/
cmd.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#![allow(clippy::module_inception)]
use std::path::PathBuf;
use clap::{ArgEnum, Parser, ValueHint};
const ENV_HELP: &str = "ENVIRONMENT VARIABLES:
_ZO_DATA_DIR Path for zoxide data files
_ZO_ECHO Print the matched directory before navigating to it when set to 1
_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";
#[derive(Debug, Parser)]
#[clap(
bin_name = env!("CARGO_PKG_NAME"),
about,
author,
after_help = ENV_HELP,
disable_help_subcommand = true,
propagate_version = true,
version = option_env!("ZOXIDE_VERSION").unwrap_or_default()
)]
pub enum Cmd {
Add(Add),
Import(Import),
Init(Init),
Query(Query),
Remove(Remove),
}
/// Add a new directory or increment its rank
#[derive(Debug, Parser)]
pub struct Add {
#[clap(min_values = 1, required = true, value_hint = ValueHint::DirPath)]
pub paths: Vec<PathBuf>,
}
/// Import entries from another application
#[derive(Debug, Parser)]
pub struct Import {
#[clap(value_hint = ValueHint::FilePath)]
pub path: PathBuf,
/// Application to import from
#[clap(arg_enum, long)]
pub from: ImportFrom,
/// Merge into existing database
#[clap(long)]
pub merge: bool,
}
#[derive(ArgEnum, Clone, Debug)]
pub enum ImportFrom {
Autojump,
Z,
}
/// Generate shell configuration
#[derive(Debug, Parser)]
pub struct Init {
#[clap(arg_enum)]
pub shell: InitShell,
/// Prevents zoxide from defining the `z` and `zi` commands
#[clap(long, alias = "no-aliases")]
pub no_cmd: bool,
/// Changes the prefix of the `z` and `zi` commands
#[clap(long, default_value = "z")]
pub cmd: String,
/// Changes how often zoxide increments a directory's score
#[clap(arg_enum, long, default_value = "pwd")]
pub hook: InitHook,
}
#[derive(ArgEnum, Clone, Copy, Debug, Eq, PartialEq)]
pub enum InitHook {
None,
Prompt,
Pwd,
}
#[derive(ArgEnum, Clone, Debug)]
pub enum InitShell {
Bash,
Elvish,
Fish,
Nushell,
Posix,
Powershell,
Xonsh,
Zsh,
}
/// Search for a directory in the database
#[derive(Debug, Parser)]
pub struct Query {
pub keywords: Vec<String>,
/// Show deleted directories
#[clap(long)]
pub all: bool,
/// 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
#[clap(long, short)]
pub score: bool,
/// Search only through current working directory
#[clap(long, short, conflicts_with = "homedir")]
pub currentdir: bool,
/// Search only through home directory
#[clap(long, short, conflicts_with = "currentdir", short = 'm')]
pub homedir: bool,
/// Exclude a path from results
#[clap(long, value_hint = ValueHint::DirPath, value_name = "path")]
pub exclude: Option<String>,
}
/// Remove a directory from the database
#[derive(Debug, Parser)]
pub struct Remove {
/// Use interactive selection
#[clap(long, short)]
pub interactive: bool,
#[clap(value_hint = ValueHint::DirPath)]
pub paths: Vec<String>,
}