Skip to content

feat: new "content" option to copy command #2447

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions yazi-config/preset/keymap-default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
9 changes: 8 additions & 1 deletion yazi-core/src/tab/commands/copy.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Loading