mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: new --content option to copy command
This change extends the copy command by introducing a new "content" option. When users use cg "content", the command reads the file's contents and copies them to the clipboard instead of just copying file paths or names.
This commit is contained in:
parent
3dc6d82b98
commit
100d62602e
2 changed files with 9 additions and 1 deletions
|
|
@ -98,6 +98,7 @@ keymap = [
|
|||
{ on = [ "c", "d" ], run = "copy dirname", desc = "Copy the directory path" },
|
||||
{ on = [ "c", "f" ], run = "copy filename", desc = "Copy the filename" },
|
||||
{ on = [ "c", "n" ], run = "copy name_without_ext", desc = "Copy the filename without extension" },
|
||||
{ on = [ "c", "g" ], run = "copy content", desc = "Copy the content" },
|
||||
|
||||
# Filter
|
||||
{ on = "f", run = "filter --smart", desc = "Filter files" },
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::{borrow::Cow, ffi::{OsStr, OsString}, path::Path};
|
||||
use std::{borrow::Cow, ffi::{OsStr, OsString}, fs, path::Path};
|
||||
|
||||
use yazi_plugin::CLIPBOARD;
|
||||
use yazi_shared::event::CmdCow;
|
||||
|
|
@ -34,6 +34,13 @@ impl Tab {
|
|||
"dirname" => opt.separator.transform(u.parent().unwrap_or(Path::new(""))),
|
||||
"filename" => opt.separator.transform(u.name()),
|
||||
"name_without_ext" => opt.separator.transform(u.file_stem().unwrap_or_default()),
|
||||
"content" => match fs::read_to_string(u.as_path()) {
|
||||
Ok(content) => Cow::Owned(OsString::from(content)),
|
||||
Err(err) => {
|
||||
yazi_proxy::AppProxy::notify_error("Error reading content", err);
|
||||
Cow::Borrowed(OsStr::new(""))
|
||||
}
|
||||
},
|
||||
_ => return,
|
||||
});
|
||||
if it.peek().is_some() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue