Skip to content

Conversation

Nicholas42
Copy link
Contributor

Hi! Very cool project, I recently started using it and have a (not too obscure in my opinion) use case: When integrating yazi with other tools, it is useful to be able to return with a non-zero exit code. An example for this is the pager for https://github.com/aurutils/aurutils

I don't think it is possible to do this via a plugin (except for maybe somehow purposefully panicking from lua), so I added an option to the quit command.

Hope this is helpful.

This is useful to integrate yazi into a workflow with other tools. An
example for this is the pager for https://github.com/aurutils/aurutils
@sxyazi
Copy link
Owner

sxyazi commented Apr 12, 2025

It's unclear to me why this is needed:

  • Does aurutils specifically require it — what is it used for?
  • You added it to the quit command, do you intend to bind different keys to quit in order to exit Yazi with different exit codes?
  • Does a command line parameter like yazi --exit-code make sense?

@Nicholas42
Copy link
Contributor Author

  • Does aurutils specifically require it — what is it used for?

The workflow in aurutils is the following: It opens a directory (the build directory for an aur package) with an external program (aurutils calls it a "pager", though I find this a bit of a weird name). The user inspects the directory (peeking into files and such) and then returns from the external program, choosing an exit code. With zero exit code, aurutils proceeds, with non-zero exit code it aborts.

To be honest, I haven't seen this workflow much outside of aurutils, but I think it is actually a very general approach that makes a lot of sense to me.

  • You added it to the quit command, do you intend to bind different keys to quit in order to exit Yazi with different exit codes?

correct

  • Does a command line parameter like yazi --exit-code make sense?

I don't know. Personally, I have no immediate use case for determining the exit code of yazi before I open it (and could emulate that with yazi && return <EXIT_CODE>

@sxyazi sxyazi requested a review from Copilot April 12, 2025 09:53
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

@sxyazi sxyazi changed the title feat: Allow custom exit code from quit feat: allow custom exit code with quit --code Apr 12, 2025
@sxyazi sxyazi requested a review from Copilot April 12, 2025 09:55
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (4)

yazi-fm/src/term.rs:92

  • Consider adding tests to ensure that the custom exit code returned by goodbye is correctly handled in various production scenarios.
pub(super) fn goodbye(f: impl FnOnce() -> i32) -> ! {

yazi-core/src/mgr/commands/quit.rs:29

  • Review the conversion to EventQuit to ensure that using Default::default() for the remaining fields does not override other intended values.
EventQuit { code: value.code, no_cwd_file: value.no_cwd_file, ..Default::default() }

yazi-fm/src/panic.rs:13

  • Verify that returning an exit code of 1 in the panic hook is consistent with the intended behavior of the application under panic scenarios.
1

yazi-core/src/mgr/commands/close.rs:6

  • [nitpick] Consider using a more descriptive name than 'Opt' to clearly indicate its role in the closing command context.
struct Opt(quit::Opt);

Copy link
Owner

@sxyazi sxyazi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@sxyazi sxyazi merged commit af92b92 into sxyazi:main Apr 12, 2025
6 checks passed
Nicholas42 added a commit to Nicholas42/yazi-rs.github.io that referenced this pull request Apr 12, 2025
Align with changes from sxyazi/yazi#2609
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants