Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add task duplicate #563

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/keybindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Keybindings for task report:

e: task {selected} edit - Open selected task in editor

y: task {selected} duplicate - Duplicate tasks

j: {selected+=1} - Move down in task report

k: {selected-=1} - Move up in task report
Expand Down
49 changes: 49 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,47 @@ impl TaskwarriorTui {
}
}

pub fn task_duplicate(&mut self) -> Result<(), String> {
if self.tasks.is_empty() {
return Ok(());
}

let task_uuids = self.selected_task_uuids();

let mut command = std::process::Command::new("task");
command.arg("rc.bulk=0");
command.arg("rc.confirmation=off");
command.arg("rc.dependency.confirmation=off");
command.arg("rc.recurrence.confirmation=off");
for task_uuid in &task_uuids {
command.arg(task_uuid.to_string());
}
command.arg("duplicate");

let output = command.output();
let r = match output {
Ok(o) => {
if o.status.success() {
Ok(())
} else {
Err(format!("Modify failed. {}", String::from_utf8_lossy(&o.stdout)))
}
}
Err(_) => Err(format!(
"Cannot run `task {:?} duplicate`. Check documentation for more information",
task_uuids,
)),
};

if task_uuids.len() == 1 {
if let Some(uuid) = task_uuids.first() {
self.current_selection_uuid = Some(*uuid);
}
}

r
}

pub async fn task_edit(&mut self) -> Result<(), String> {
if self.tasks.is_empty() {
return Ok(());
Expand Down Expand Up @@ -2617,6 +2658,14 @@ impl TaskwarriorTui {
self.mode = Mode::Tasks(Action::Error);
}
}
} else if input == self.keyconfig.duplicate {
match self.task_duplicate() {
Ok(_) => self.update(true).await?,
Err(e) => {
self.error = Some(e);
self.mode = Mode::Tasks(Action::Error);
}
}
} else if input == self.keyconfig.undo {
if self.config.uda_task_report_prompt_on_undo {
self.mode = Mode::Tasks(Action::UndoPrompt);
Expand Down
5 changes: 5 additions & 0 deletions src/keyconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct KeyConfig {
pub select_all: KeyCode,
pub undo: KeyCode,
pub edit: KeyCode,
pub duplicate: KeyCode,
pub modify: KeyCode,
pub shell: KeyCode,
pub log: KeyCode,
Expand Down Expand Up @@ -70,6 +71,7 @@ impl Default for KeyConfig {
select_all: KeyCode::Char('V'),
undo: KeyCode::Char('u'),
edit: KeyCode::Char('e'),
duplicate: KeyCode::Char('y'),
modify: KeyCode::Char('m'),
shell: KeyCode::Char('!'),
log: KeyCode::Char('l'),
Expand Down Expand Up @@ -123,6 +125,7 @@ impl KeyConfig {
let select_all = Self::get_config("uda.taskwarrior-tui.keyconfig.select-all", data);
let undo = Self::get_config("uda.taskwarrior-tui.keyconfig.undo", data);
let edit = Self::get_config("uda.taskwarrior-tui.keyconfig.edit", data);
let duplicate = Self::get_config("uda.taskwarrior-tui.keyconfig.duplicate", data);
let modify = Self::get_config("uda.taskwarrior-tui.keyconfig.modify", data);
let shell = Self::get_config("uda.taskwarrior-tui.keyconfig.shell", data);
let log = Self::get_config("uda.taskwarrior-tui.keyconfig.log", data);
Expand Down Expand Up @@ -160,6 +163,7 @@ impl KeyConfig {
self.select_all = select_all.unwrap_or(self.select_all);
self.undo = undo.unwrap_or(self.undo);
self.edit = edit.unwrap_or(self.edit);
self.duplicate = edit.unwrap_or(self.duplicate);
self.modify = modify.unwrap_or(self.modify);
self.shell = shell.unwrap_or(self.shell);
self.log = log.unwrap_or(self.log);
Expand Down Expand Up @@ -202,6 +206,7 @@ impl KeyConfig {
&self.quick_tag,
&self.undo,
&self.edit,
&self.duplicate,
&self.modify,
&self.shell,
&self.log,
Expand Down
Loading