Add :write
to nix repl #182
Labels
No labels
Area/build-packaging
Area/cli
Area/evaluator
Area/fetching
Area/flakes
Area/language
Area/profiles
Area/protocol
Area/releng
Area/remote-builds
Area/repl
Area/store
bug
crash 💥
Cross Compilation
devx
docs
Downstream Dependents
E/easy
E/hard
E/help wanted
E/reproducible
E/requires rearchitecture
imported
Needs Langver
OS/Linux
OS/macOS
performance
regression
release-blocker
RFD
stability
Status
blocked
Status
invalid
Status
postponed
Status
wontfix
testing
testing/flakey
ux
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lix-project/lix#182
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Is your feature request related to a problem? Please describe.
Often I quickly try things in the repl to see if they work but it's annoying to then type them twice or copy and paste it by hand.
Describe the solution you'd like
It would be nice to have something like
:w
/:write
that expects a path and just writes a file with all successfully evaled "commands" and removes repl specific things like:p
from the code. Additionally it would also be nice if it also ran a formatter on the code before writing to the file (for example nixfmt-rfc-style since it's now the default for nixpkgs)Can you elaborate a bit more on the use case for mirroring REPL commands to a file?
Part of the reason I'm asking is that many REPLs provide a
.history
file containing commands the user has entered, but it sounds like that's not exactly what you're looking for but I want to better understand how you intend to use this.Minor complication worthy of note: the REPL supports lines of the form
key = value
that add bindings scoped to the REPL session, which can be overridden with later commands. These would need to be translated (presumably to let bindings), but they also interact differently than let bindings (they aren't recursive iwrc), so there'd need to be some figuring-out of the correct semantics there.Uh sure, I often draft up some stuff stuff in the repl and it would be convenient not to have to type it twice so writing it to a file would be quite nice to not have to type it twice.
(I'm aware that I can also just write the code in a editor and use
nix repl --file $file
)(…TWL about
nix repl --file
. Damn.)Would a
.history
file solve your issue? That seems to be like a more standard REPL feature that lots of line editing packages support out of the box. I think that would be simpler than rolling our own custom thing that filters post-processes the commands before they are written out.The thing about a history file is it doesn't let you grab the current session only. I think that's part of the requirements here.
I believe making the history file location configurable (e.g. via a command-line option or REPL command) would address that
This is just a nice to have thing, I would personally be interested in, bun non of you have to spend any time on this.
I don't think so because as jade said having a per session history would be required here, but I may be missing your point.
What I'm proposing is that if we added support for history files then we could include support for specifying the path to use for the history file in the REPL, like this:
In other words, I'm suggesting two amendments to your original proposal:
:history
/:h
instead of:write
/:w
Unless I'm missing something I think that still addresses your use case
one issue with this is that you can't do it retroactively which is a bit of a limitation, i think?
Yeah, that's true, although the commands wouldn't have been lost; they would have just been written to the default history file path.
Another possible option that might give the best of both worlds is to automatically generate a unique history file path for each session by default so that the user doesn't even have to run any command.