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