diff --git a/app/src/app.rs b/app/src/app.rs index d59fd759..ef308dfa 100644 --- a/app/src/app.rs +++ b/app/src/app.rs @@ -1,5 +1,5 @@ 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 config::{keymap::{Control, Key, KeymapLayer}, BOOT}; @@ -167,6 +167,17 @@ impl App { } 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 { tasks.file_open_with(&opener, &targets.into_iter().map(|(f, _)| f).collect::>()); } else { diff --git a/config/src/boot/boot.rs b/config/src/boot/boot.rs index fbb68652..e15d8870 100644 --- a/config/src/boot/boot.rs +++ b/config/src/boot/boot.rs @@ -2,32 +2,51 @@ use std::{env, fs, os::unix::prelude::OsStrExt, path::{Path, PathBuf}, time::{se use clap::{command, Parser}; use md5::{Digest, Md5}; +use shared::absolute_path; #[derive(Debug)] pub struct Boot { pub cwd: PathBuf, - pub cwd_file: Option, pub cache_dir: PathBuf, pub state_dir: PathBuf, + + pub cwd_file: Option, + pub chooser_file: Option, } #[derive(Debug, Parser)] #[command(name = "yazi")] #[command(version = "0.1.3")] struct Args { + /// Set the current working directory + #[arg(long, short)] + cwd: Option, + /// Write the cwd on exit to this file #[arg(long)] - cwd_file: Option, + cwd_file: Option, + /// Write the selected files on open emitted by the chooser mode + #[arg(long)] + chooser_file: Option, } impl Default for Boot { fn default() -> Self { 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 { - cwd: env::current_dir().unwrap_or("/".into()), - cwd_file: args.cwd_file, + cwd: cwd.unwrap_or("/".into()), cache_dir: env::temp_dir().join("yazi"), 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() { diff --git a/core/src/external/clipboard.rs b/core/src/external/clipboard.rs index e39813d5..48a426ac 100644 --- a/core/src/external/clipboard.rs +++ b/core/src/external/clipboard.rs @@ -28,4 +28,3 @@ pub async fn clipboard_set(s: &str) -> Result<()> { bail!("failed to set clipboard") } - diff --git a/core/src/select/select.rs b/core/src/select/select.rs index ca9a1626..fbd180e6 100644 --- a/core/src/select/select.rs +++ b/core/src/select/select.rs @@ -1,8 +1,7 @@ use anyhow::{anyhow, Result}; -use shared::tty_size; use tokio::sync::oneshot::Sender; -use super::{SelectOpt, SELECT_PADDING}; +use super::SelectOpt; use crate::Position; #[derive(Default)] diff --git a/core/src/which/mod.rs b/core/src/which/mod.rs index 93c339a1..6bdddcdc 100644 --- a/core/src/which/mod.rs +++ b/core/src/which/mod.rs @@ -1,4 +1,3 @@ mod which; pub use which::*; -