-
-
Notifications
You must be signed in to change notification settings - Fork 109
Implement changing command
s via keyboard shortcut
#358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I welcome other user's feedback on this but having such controls in the command is not a direction I like. Comments welcome both on this specific approach and on other ones regarding the general need. |
It's an interesting idea, however I'm not sure what advantage it has over separate jobs. I'd propose that separate jobs would be easier to understand overall. Only advantage that stands out to me is everything would be closer to each other but I'm not sure that makes up for the additional complexity. That said one thing I have wanted is a way to be able to get a list of the available jobs while bacon is running without needing to set shortcuts for each of them. If there were a list I could scroll with up and down that would make my life easier and maybe also address this need. @narpfel would that make this no longer needed in your opinion? |
This looks like a (good and) completely distinct problem that would be better discussed either directly in a dedicated issue or on the chat. |
I'm open to both. This issue just reminded me of that. That's all. It's a thing I want but only just a little as I only need to setup the shortcuts once per project and then I can get a list in the help. |
For just a single option I agree, separate jobs are simpler (though even then I’d prefer to not duplicate anything if possible). However, each additional option increases the number of jobs (and the number of keyboard shortcuts necessary to trigger them) by a factor of two. My personal use case (which would require four copies) looks like this (narpfel/panko@main...bacon-maybe-treat-error-as-bug): [jobs.run]
command = [
"cargo", "run",
"--profile=clif",
"--color", "always",
"--",
{ if = "treat-error-as-bug", then = "--treat-error-as-bug" },
"--print=layout",
"--print=codegen",
"-o/tmp/main.S",
{ if = "second-input-file", then = "c/test.c", else = "c/main.c"},
]
need_stdout = true
allow_warnings = true
background = true
watch = ["../c"]
env.CLICOLOR_FORCE = "1"
[keybindings]
g = "toggle-option(treat-error-as-bug)"
2 = "toggle-option(second-input-file)" Another advantage this PR has over duplicating jobs is that transitions between jobs become easier: if I want to toggle Here’s an example with two options (four copies of the job) that I randomly found through the Github search: https://github.com/itsscb/posh-parser/blob/f54a302118ff931b0e4ca63c3737536c50e359f6/bacon.toml#L19-L114 With this PR, it could be written as [jobs.clippy]
command = [
"cargo",
"clippy",
{ if = "all-targets", then = "--all-targets" },
"--color",
"always",
{ if = "workspace", then = "--workspace" },
"--",
"-W",
"clippy::all",
"-W",
"clippy::pedantic",
"-W",
"clippy::nursery",
"-W",
"clippy::expect_used",
"-W",
"clippy::unwrap_used",
]
need_stdout = false Here’s an example with six copies of basically the same job: https://github.com/kaleidawave/ezno/blob/506be8be8b6f1de2423ecab6413b31e3cb0ce58c/bacon.toml#L73-L169. This PR does not directly help in simplifying this, but it’s a relatively simple extension to allow options with dynamic values (none/ Most |
This PR implements a feature to change job
command
s via keyboard shortcut, instead of changingbacon.toml
or switching between different jobs.This is done by allowing simple conditionals of the form
{ if = <option>, then = <optional-value-if-option-is-set>, else = <optional-value-if-option-is-unset> }
as elements of thecommand
array for jobs.Options start out as unset and can be toggled by the
toggle-option(...)
action. If the option is set, thethen
branch is passed to the command; else theelse
value is passed.If the
then
orelse
clause is not given, the element is removed from the command invocation if that branch would have been taken.Example:
Initially, this starts out as printing
Can be altered based on keyboard input
, but pressing1
or2
toggles betweenaltered
/changed
andinput
/shortcuts
respectively. Pressing.
adds a.
to the end of the sentence.For a real world application of this, see narpfel/panko@023466d. I use
bacon run
to run the application, and sometimes I want to pass an optional command line flag, but most of the time, I don’t want that flag.TODO
(I wanted to get feedback if this is a feature you’re interested in before spending time on these items.)