Support bulk edit

This commit is contained in:
phanium 2024-04-25 19:10:04 +08:00
parent 5d8a7ea7b2
commit 72c0b59723
2 changed files with 15 additions and 12 deletions

View File

@ -67,11 +67,11 @@ pub struct Edit {
#[derive(Clone, Debug, Subcommand)] #[derive(Clone, Debug, Subcommand)]
pub enum EditCommand { pub enum EditCommand {
#[clap(hide = true)] #[clap(hide = true)]
Decrement { path: String }, Decrement { paths: Vec<String> },
#[clap(hide = true)] #[clap(hide = true)]
Delete { path: String }, Delete { paths: Vec<String> },
#[clap(hide = true)] #[clap(hide = true)]
Increment { path: String }, Increment { paths: Vec<String> },
#[clap(hide = true)] #[clap(hide = true)]
Reload, Reload,
} }

View File

@ -15,11 +15,15 @@ impl Run for Edit {
match &self.cmd { match &self.cmd {
Some(cmd) => { Some(cmd) => {
match cmd { match cmd {
EditCommand::Decrement { path } => db.add(path, -1.0, now), EditCommand::Decrement { paths } => paths.iter().for_each(|path| {
EditCommand::Delete { path } => { db.add(path, -1.0, now);
}),
EditCommand::Delete { paths } => paths.iter().for_each(|path| {
db.remove(path); db.remove(path);
}),
EditCommand::Increment { paths } => {
paths.iter().for_each(|path| db.add(path, 1.0, now))
} }
EditCommand::Increment { path } => db.add(path, 1.0, now),
EditCommand::Reload => {} EditCommand::Reload => {}
} }
db.save()?; db.save()?;
@ -50,17 +54,16 @@ impl Edit {
// Search result // Search result
"--no-sort", "--no-sort",
// Interface // Interface
"--multi",
"--bind=\ "--bind=\
btab:up,\
ctrl-r:reload(zoxide edit reload),\ ctrl-r:reload(zoxide edit reload),\
ctrl-d:reload(zoxide edit delete {2..}),\ ctrl-d:reload(zoxide edit delete {+2..}),\
ctrl-w:reload(zoxide edit increment {2..}),\ ctrl-w:reload(zoxide edit increment {+2..}),\
ctrl-s:reload(zoxide edit decrement {2..}),\ ctrl-s:reload(zoxide edit decrement {+2..}),\
ctrl-z:ignore,\ ctrl-z:ignore,\
double-click:ignore,\ double-click:ignore,\
enter:abort,\ enter:abort,\
start:reload(zoxide edit reload),\ start:reload(zoxide edit reload)",
tab:down",
"--cycle", "--cycle",
"--keep-right", "--keep-right",
// Layout // Layout