mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: add new --no-cwd-file option to quit command for flexible cwd-file setting (#245)
This commit is contained in:
parent
6da04c7eb5
commit
4527044547
6 changed files with 20 additions and 16 deletions
|
|
@ -25,8 +25,8 @@ impl App {
|
|||
|
||||
while let Some(event) = app.signals.recv().await {
|
||||
match event {
|
||||
Event::Quit => {
|
||||
app.dispatch_quit();
|
||||
Event::Quit(no_cwd_file) => {
|
||||
app.dispatch_quit(no_cwd_file);
|
||||
break;
|
||||
}
|
||||
Event::Key(key) => app.dispatch_key(key),
|
||||
|
|
@ -41,8 +41,8 @@ impl App {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn dispatch_quit(&mut self) {
|
||||
if let Some(p) = &BOOT.cwd_file {
|
||||
fn dispatch_quit(&mut self, no_cwd_file: bool) {
|
||||
if let Some(p) = BOOT.cwd_file.as_ref().filter(|_| !no_cwd_file) {
|
||||
let cwd = self.cx.manager.cwd().as_os_str();
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
|
|
@ -200,7 +200,7 @@ impl App {
|
|||
use std::os::unix::ffi::OsStrExt;
|
||||
std::fs::write(p, paths.as_bytes()).ok();
|
||||
}
|
||||
return emit!(Quit);
|
||||
return emit!(Quit(false));
|
||||
}
|
||||
|
||||
if let Some(opener) = opener {
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ impl Executor {
|
|||
fn manager(cx: &mut Ctx, exec: &Exec) -> bool {
|
||||
match exec.cmd.as_str() {
|
||||
"escape" => cx.manager.active_mut().escape(),
|
||||
"quit" => cx.manager.quit(&cx.tasks),
|
||||
"quit" => cx.manager.quit(&cx.tasks, exec.named.contains_key("no-cwd-file")),
|
||||
"close" => cx.manager.close(&cx.tasks),
|
||||
"suspend" => cx.manager.suspend(),
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ impl Signals {
|
|||
while let Some(signal) = signals.next().await {
|
||||
match signal {
|
||||
SIGHUP | SIGTERM | SIGQUIT | SIGINT => {
|
||||
if tx.send(Event::Quit).is_err() {
|
||||
if tx.send(Event::Quit(false)).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
[manager]
|
||||
|
||||
keymap = [
|
||||
{ on = [ "<Esc>" ], exec = "escape", desc = "Exit visual mode, clear selected, or cancel search" },
|
||||
{ on = [ "q" ], exec = "quit", desc = "Exit the process" },
|
||||
{ on = [ "<C-q>" ], exec = "close", desc = "Close the current tab, or quit if it is last tab" },
|
||||
{ on = [ "<C-z>" ], exec = "suspend", desc = "Suspend the process" },
|
||||
{ on = [ "<Esc>" ], exec = "escape", desc = "Exit visual mode, clear selected, or cancel search" },
|
||||
{ on = [ "q" ], exec = "quit", desc = "Exit the process" },
|
||||
{ on = [ "Q" ], exec = "quit --no-cwd-file", desc = "Exit the process without writing cwd-file" },
|
||||
{ on = [ "<C-q>" ], exec = "close", desc = "Close the current tab, or quit if it is last tab" },
|
||||
{ on = [ "<C-z>" ], exec = "suspend", desc = "Suspend the process" },
|
||||
|
||||
# Navigation
|
||||
{ on = [ "k" ], exec = "arrow -1", desc = "Move cursor up" },
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::manager::PreviewLock;
|
|||
static TX: RoCell<UnboundedSender<Event>> = RoCell::new();
|
||||
|
||||
pub enum Event {
|
||||
Quit,
|
||||
Quit(bool), // no-cwd-file
|
||||
Key(KeyEvent),
|
||||
Paste(String),
|
||||
Render(String),
|
||||
|
|
@ -54,6 +54,9 @@ impl Event {
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! emit {
|
||||
(Quit($no_cwd_file:expr)) => {
|
||||
$crate::Event::Quit($no_cwd_file).emit();
|
||||
};
|
||||
(Key($key:expr)) => {
|
||||
$crate::Event::Key($key).emit();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -88,10 +88,10 @@ impl Manager {
|
|||
false
|
||||
}
|
||||
|
||||
pub fn quit(&self, tasks: &Tasks) -> bool {
|
||||
pub fn quit(&self, tasks: &Tasks, no_cwd_file: bool) -> bool {
|
||||
let tasks = tasks.len();
|
||||
if tasks == 0 {
|
||||
emit!(Quit);
|
||||
emit!(Quit(no_cwd_file));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ impl Manager {
|
|||
|
||||
if let Some(Ok(choice)) = result.recv().await {
|
||||
if choice == "y" || choice == "Y" {
|
||||
emit!(Quit);
|
||||
emit!(Quit(no_cwd_file));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -113,7 +113,7 @@ impl Manager {
|
|||
if self.tabs.len() > 1 {
|
||||
return self.tabs.close(self.tabs.idx());
|
||||
}
|
||||
self.quit(tasks)
|
||||
self.quit(tasks, false)
|
||||
}
|
||||
|
||||
pub fn suspend(&mut self) -> bool {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue