forked from extern/nushell
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:
parent
ecb67fee40
commit
741d7b9f10
@ -14,6 +14,8 @@ pub struct RemoveArgs {
|
|||||||
pub recursive: Tagged<bool>,
|
pub recursive: Tagged<bool>,
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub trash: Tagged<bool>,
|
pub trash: Tagged<bool>,
|
||||||
|
#[allow(unused)]
|
||||||
|
pub permanent: Tagged<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@ -29,6 +31,11 @@ impl WholeStreamCommand for Remove {
|
|||||||
"use the platform's recycle bin instead of permanently deleting",
|
"use the platform's recycle bin instead of permanently deleting",
|
||||||
Some('t'),
|
Some('t'),
|
||||||
)
|
)
|
||||||
|
.switch(
|
||||||
|
"permanent",
|
||||||
|
"don't use recycle bin, delete permanently",
|
||||||
|
Some('p'),
|
||||||
|
)
|
||||||
.switch("recursive", "delete subdirectories recursively", Some('r'))
|
.switch("recursive", "delete subdirectories recursively", Some('r'))
|
||||||
.rest(SyntaxShape::Pattern, "the file path(s) to remove")
|
.rest(SyntaxShape::Pattern, "the file path(s) to remove")
|
||||||
}
|
}
|
||||||
@ -48,7 +55,7 @@ impl WholeStreamCommand for Remove {
|
|||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![
|
vec![
|
||||||
Example {
|
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",
|
example: "rm file.txt",
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
@ -57,6 +64,11 @@ impl WholeStreamCommand for Remove {
|
|||||||
example: "rm --trash file.txt",
|
example: "rm --trash file.txt",
|
||||||
result: None,
|
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 name = args.call_info.name_tag.clone();
|
||||||
let shell_manager = args.shell_manager.clone();
|
let shell_manager = args.shell_manager.clone();
|
||||||
let (args, _): (RemoveArgs, _) = args.process(®istry).await?;
|
let (args, _): (RemoveArgs, _) = args.process(®istry).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 {
|
while let Some(item) = result.next().await {
|
||||||
yield item;
|
yield item;
|
||||||
}
|
}
|
||||||
|
@ -485,6 +485,7 @@ impl Shell for FilesystemShell {
|
|||||||
rest: targets,
|
rest: targets,
|
||||||
recursive,
|
recursive,
|
||||||
trash: _trash,
|
trash: _trash,
|
||||||
|
permanent: _permanent,
|
||||||
}: RemoveArgs,
|
}: RemoveArgs,
|
||||||
name: Tag,
|
name: Tag,
|
||||||
path: &str,
|
path: &str,
|
||||||
@ -565,7 +566,8 @@ impl Shell for FilesystemShell {
|
|||||||
let result;
|
let result;
|
||||||
#[cfg(feature = "trash-support")]
|
#[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)
|
trash::remove(f)
|
||||||
.map_err(|e| f.to_string_lossy())
|
.map_err(|e| f.to_string_lossy())
|
||||||
} else if metadata.is_file() {
|
} else if metadata.is_file() {
|
||||||
|
@ -29,19 +29,21 @@ Syntax: `config {flags}`
|
|||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
|
|
||||||
| Variable | Type | Description |
|
| Variable | Type | Description |
|
||||||
| ------------------ | ---------------------- | ------------------------------------------------------------------- |
|
| ------------------ | ---------------------- | ------------------------------------------------------------------------- |
|
||||||
| path | table of strings | PATH to use to find binaries |
|
| path | table of strings | PATH to use to find binaries |
|
||||||
| env | row | the environment variables to pass to external commands |
|
| env | row | the environment variables to pass to external commands |
|
||||||
| ctrlc_exit | boolean | whether or not to exit Nu after multiple ctrl-c presses |
|
| ctrlc_exit | boolean | whether or not to exit Nu after multiple ctrl-c presses |
|
||||||
| table_mode | "light" or other | enable lightweight or normal tables |
|
| table_mode | "light" or other | enable lightweight or normal tables |
|
||||||
| edit_mode | "vi" or "emacs" | changes line editing to "vi" or "emacs" mode |
|
| 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 |
|
| 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) |
|
| 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 |
|
| 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. |
|
| 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
|
## Examples
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user