mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: choose-file mode (#69)
This commit is contained in:
parent
1135c13d0f
commit
b70f83ced7
5 changed files with 36 additions and 9 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
use core::{emit, files::FilesOp, input::InputMode, Event};
|
use core::{emit, files::FilesOp, input::InputMode, Event};
|
||||||
use std::os::unix::prelude::OsStrExt;
|
use std::{ffi::OsString, os::unix::prelude::OsStrExt};
|
||||||
|
|
||||||
use anyhow::{Ok, Result};
|
use anyhow::{Ok, Result};
|
||||||
use config::{keymap::{Control, Key, KeymapLayer}, BOOT};
|
use config::{keymap::{Control, Key, KeymapLayer}, BOOT};
|
||||||
|
|
@ -167,6 +167,17 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::Open(targets, opener) => {
|
Event::Open(targets, opener) => {
|
||||||
|
if let Some(p) = &BOOT.chooser_file {
|
||||||
|
let paths = targets.into_iter().fold(OsString::new(), |mut s, (p, _)| {
|
||||||
|
s.push(p);
|
||||||
|
s.push("\n");
|
||||||
|
s
|
||||||
|
});
|
||||||
|
|
||||||
|
std::fs::write(p, paths.as_bytes()).ok();
|
||||||
|
return emit!(Quit);
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(opener) = opener {
|
if let Some(opener) = opener {
|
||||||
tasks.file_open_with(&opener, &targets.into_iter().map(|(f, _)| f).collect::<Vec<_>>());
|
tasks.file_open_with(&opener, &targets.into_iter().map(|(f, _)| f).collect::<Vec<_>>());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -2,32 +2,51 @@ use std::{env, fs, os::unix::prelude::OsStrExt, path::{Path, PathBuf}, time::{se
|
||||||
|
|
||||||
use clap::{command, Parser};
|
use clap::{command, Parser};
|
||||||
use md5::{Digest, Md5};
|
use md5::{Digest, Md5};
|
||||||
|
use shared::absolute_path;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Boot {
|
pub struct Boot {
|
||||||
pub cwd: PathBuf,
|
pub cwd: PathBuf,
|
||||||
pub cwd_file: Option<PathBuf>,
|
|
||||||
pub cache_dir: PathBuf,
|
pub cache_dir: PathBuf,
|
||||||
pub state_dir: PathBuf,
|
pub state_dir: PathBuf,
|
||||||
|
|
||||||
|
pub cwd_file: Option<PathBuf>,
|
||||||
|
pub chooser_file: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[command(name = "yazi")]
|
#[command(name = "yazi")]
|
||||||
#[command(version = "0.1.3")]
|
#[command(version = "0.1.3")]
|
||||||
struct Args {
|
struct Args {
|
||||||
|
/// Set the current working directory
|
||||||
|
#[arg(long, short)]
|
||||||
|
cwd: Option<PathBuf>,
|
||||||
|
|
||||||
/// Write the cwd on exit to this file
|
/// Write the cwd on exit to this file
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
cwd_file: Option<PathBuf>,
|
cwd_file: Option<PathBuf>,
|
||||||
|
/// Write the selected files on open emitted by the chooser mode
|
||||||
|
#[arg(long)]
|
||||||
|
chooser_file: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Boot {
|
impl Default for Boot {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
|
let cwd = args
|
||||||
|
.cwd
|
||||||
|
.map(|p| futures::executor::block_on(absolute_path(p)))
|
||||||
|
.and_then(|p| p.is_dir().then_some(p))
|
||||||
|
.or_else(|| env::current_dir().ok());
|
||||||
|
|
||||||
let boot = Self {
|
let boot = Self {
|
||||||
cwd: env::current_dir().unwrap_or("/".into()),
|
cwd: cwd.unwrap_or("/".into()),
|
||||||
cwd_file: args.cwd_file,
|
|
||||||
cache_dir: env::temp_dir().join("yazi"),
|
cache_dir: env::temp_dir().join("yazi"),
|
||||||
state_dir: xdg::BaseDirectories::with_prefix("yazi").unwrap().get_state_home(),
|
state_dir: xdg::BaseDirectories::with_prefix("yazi").unwrap().get_state_home(),
|
||||||
|
|
||||||
|
cwd_file: args.cwd_file,
|
||||||
|
chooser_file: args.chooser_file,
|
||||||
};
|
};
|
||||||
|
|
||||||
if !boot.cache_dir.is_dir() {
|
if !boot.cache_dir.is_dir() {
|
||||||
|
|
|
||||||
1
core/src/external/clipboard.rs
vendored
1
core/src/external/clipboard.rs
vendored
|
|
@ -28,4 +28,3 @@ pub async fn clipboard_set(s: &str) -> Result<()> {
|
||||||
|
|
||||||
bail!("failed to set clipboard")
|
bail!("failed to set clipboard")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use shared::tty_size;
|
|
||||||
use tokio::sync::oneshot::Sender;
|
use tokio::sync::oneshot::Sender;
|
||||||
|
|
||||||
use super::{SelectOpt, SELECT_PADDING};
|
use super::SelectOpt;
|
||||||
use crate::Position;
|
use crate::Position;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
mod which;
|
mod which;
|
||||||
|
|
||||||
pub use which::*;
|
pub use which::*;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue