Add rm_always_trash option to config (#1869)

* Add `rm_always_trash` option to config

* Add `--permanent` flag to `rm`

* `rm`: error if both `-t` and `-p` are present

Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
This commit is contained in:
Oleksii Filonenko 2020-05-30 21:31:34 +03:00 committed by GitHub
parent ecb67fee40
commit 741d7b9f10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 15 deletions

View File

@ -14,6 +14,8 @@ pub struct RemoveArgs {
pub recursive: Tagged<bool>,
#[allow(unused)]
pub trash: Tagged<bool>,
#[allow(unused)]
pub permanent: Tagged<bool>,
}
#[async_trait]
@ -29,6 +31,11 @@ impl WholeStreamCommand for Remove {
"use the platform's recycle bin instead of permanently deleting",
Some('t'),
)
.switch(
"permanent",
"don't use recycle bin, delete permanently",
Some('p'),
)
.switch("recursive", "delete subdirectories recursively", Some('r'))
.rest(SyntaxShape::Pattern, "the file path(s) to remove")
}
@ -48,7 +55,7 @@ impl WholeStreamCommand for Remove {
fn examples(&self) -> Vec<Example> {
vec![
Example {
description: "Delete a file",
description: "Delete or move a file to the system trash (depending on 'rm_always_trash' config option)",
example: "rm file.txt",
result: None,
},
@ -57,6 +64,11 @@ impl WholeStreamCommand for Remove {
example: "rm --trash file.txt",
result: None,
},
Example {
description: "Delete a file permanently",
example: "rm --permanent file.txt",
result: None,
},
]
}
}
@ -67,7 +79,15 @@ fn rm(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, She
let name = args.call_info.name_tag.clone();
let shell_manager = args.shell_manager.clone();
let (args, _): (RemoveArgs, _) = args.process(&registry).await?;
let mut result = shell_manager.rm(args, name)?;
let mut result = if args.trash.item && args.permanent.item {
OutputStream::one(Err(ShellError::labeled_error(
"only one of --permanent and --trash can be used",
"conflicting flags",
name
)))
} else {
shell_manager.rm(args, name)?
};
while let Some(item) = result.next().await {
yield item;
}

View File

@ -485,6 +485,7 @@ impl Shell for FilesystemShell {
rest: targets,
recursive,
trash: _trash,
permanent: _permanent,
}: RemoveArgs,
name: Tag,
path: &str,
@ -565,7 +566,8 @@ impl Shell for FilesystemShell {
let result;
#[cfg(feature = "trash-support")]
{
result = if _trash.item {
let rm_always_trash = config::config(Tag::unknown())?.get("rm_always_trash").map(|val| val.is_true()).unwrap_or(false);
result = if _trash.item || (rm_always_trash && !_permanent.item) {
trash::remove(f)
.map_err(|e| f.to_string_lossy())
} else if metadata.is_file() {

View File

@ -29,19 +29,21 @@ Syntax: `config {flags}`
### Variables
| Variable | Type | Description |
| ------------------ | ---------------------- | ------------------------------------------------------------------- |
| path | table of strings | PATH to use to find binaries |
| env | row | the environment variables to pass to external commands |
| ctrlc_exit | boolean | whether or not to exit Nu after multiple ctrl-c presses |
| table_mode | "light" or other | enable lightweight or normal tables |
| edit_mode | "vi" or "emacs" | changes line editing to "vi" or "emacs" mode |
| key_timeout | integer (milliseconds) | vi: the delay to wait for a longer key sequence after ESC |
| history_size | integer | maximum entries that will be stored in history (100,000 default) |
| completion_mode | "circular" or "list" | changes completion type to "circular" (default) or "list" mode |
| Variable | Type | Description |
| ------------------ | ---------------------- | ------------------------------------------------------------------------- |
| path | table of strings | PATH to use to find binaries |
| env | row | the environment variables to pass to external commands |
| ctrlc_exit | boolean | whether or not to exit Nu after multiple ctrl-c presses |
| table_mode | "light" or other | enable lightweight or normal tables |
| edit_mode | "vi" or "emacs" | changes line editing to "vi" or "emacs" mode |
| key_timeout | integer (milliseconds) | vi: the delay to wait for a longer key sequence after ESC |
| history_size | integer | maximum entries that will be stored in history (100,000 default) |
| completion_mode | "circular" or "list" | changes completion type to "circular" (default) or "list" mode |
| no_auto_pivot | boolean | whether or not to automatically pivot single-row results |
| complete_from_path | boolean | whether or not to complete names of binaries on PATH (default true) |
| rm_always_trash | boolean | whether or not to always use system trash when no flags are given to `rm` |
| pivot_mode | "auto" or "always" or "never" | "auto" will only pivot single row tables if the output is greater than the terminal width. "always" will always pivot single row tables. "never" will never pivot single row tables. |
| complete_from_path | boolean | whether or not to complete names of binaries on PATH (default true) |
| plugin_dirs | table of strings | additional directories to search for plugins during startup |
| plugin_dirs | table of strings | additional directories to search for plugins during startup |
## Examples