Closed Jwhiles closed 4 years ago
Thanks for the PR! Do you know there is a history (cursor up) so you can just rerun the same command easily? There will also be tab-completion in the future for paths and maybe even a reverse history search.
All of this is of course already possible when using the command-line because a shell already provides all this functionality (druid CLI doesn't have run
though, only upload at the moment).
Would that also work for you usecase?
In general I'd say just use r
, this is doing the same thing just slightly different based on some past state.
Never seen a tool that does that, history is usually the more generic approach to solve this problem.
Having done some more script development now, I think this is pretty useful, since digging through history to find your script can be annoying when you're running a lot of commands interactively, either to troubleshoot your script while developing it or to experiment with calling functions / setting variables manually. I think probably it would make a lot of sense for this to be the behavior of r
without arguments if you have previously run a script during the current druid session -- saves a slot for some future single-letter druid command, and probably is a more common use case than always looking for sketch.lua in the current directory. I suppose you could achieve this functionality with the current revision of druid by always saving a script you're working on to sketch.lua in the working directory.
An alternative way to achieve similar convenience might be to tell druid to watch a script, and it would automatically run the file again whenever you save it.
Sorry @simonvanderveldt - I missed the original reply here.
My motivation for adding this was to emulate my workflow in Haskell/PureScript REPLs, where it is possible to reload active modules with a :r
command.
@csboling it's a good point that working in sketch.lua allows quick reloading! I also considered using a watcher on druid itself, but I think that adds some difficulties around running / re-running other commands in the REPL.
I've updated my PR so integrate the 'again' command into the run command.
Happy to close this PR if this feature isn't needed by the way - I can keep this for my personal use :)
I'm late to this party, but I think it makes sense. I actually pulled all references to using plain r
(without a filename) out of the docs, as it relies on druid being run from a particular folder (and there's no way to know that from inside of druid).
I do like this workflow change though! I typically work in a single file and continually r <name>
to refresh my changes.
The code could be simplified by making the global declaration last_script = './sketch.lua'
. However, as the existance of this file is unknown, perhaps it should just default to ''
and the first r
invocation requires a filename?
Hey at @trentgill !
Sorry for the super slow response - but I've only just found the right opportunity to start messing with my crow again! I've updated the PR to remove sketch from the r
command. If you're still keen on this change, it would be great to get it merged - otherwise I'm happy to close this PR :)
@Jwhiles Thanks for this! I had to slide a few things around with the big refactor that's happened, but the functionality is great and now rolled into the main branch!
I found myself wanting this command when playing with crow. I also considered that if
r
is used without a parameter maybe it could re-run the last script instead of 'sketch.lua'.