Put executed commands in history
zeke opened this issue Β· 11 comments
I wish I could use ntl
to find a command, run it, and then the next time I want to run that same command again, I can just arrow-up in my shell and run it again, instead of running ntl
and arrowing through the options a second time.
Maybe the shell-history module would make this easy.
I think most shells don't write to the history file until the shell exits, so something like this might be necessary: https://stackoverflow.com/questions/842338/how-do-i-tell-zsh-to-write-the-current-shells-history-to-my-history-file
oh yeah! I feel you, this happened with me too many times already π€ how come I never thought about opening an issue before π
thank you again @zeke I'll def give this one a try once I'm done with all the refactor
it'd be nice to have a small node module taking care of that, I see Sindre has one for reading from it... https://github.com/sindresorhus/shell-history
I've done some research on this for my own project and couldn't find a way for this to be done (short of manually writing to the user's history file, which would involve either guessing where it is or trying to figure that our from configs, and even then it's not recommended; also, print -s
and history -s
won't work unfortunately).
Do let me know if you find a way!
hi @samhh I'm trying to get back at this and I was wondering - could you expand a bit more on why history -s
wouldn't work? π€at first that seems like the easy route π
Unfortunately I can't remember, it's been a while! Please let me know if you make any progress on this.
hehehe no pb π I did a quick test yesterday and figured out that wouldn't work since node spawn separate processes to run all those commands πso I don't think they can share the same history like that...
I even gave it a try using https://www.npmjs.com/package/kexec but with no luck either π
oh well, I should pb document here that a while ago I took a deep dive into the way bash and other shells handle history only to confirm that it's indeed impossible to manipulate it from any form of scripting (which I guess is great security-wise)
I think the best we can do is have an extra option for running a previously selected task (as suggested in #28). Another related quality of life improvement would be to at least pre-select the latest choice so that you may just hit ENTER twice in order to re-run the previous cmd
π’
β¦ so this can be closed, right?
attention everyone π£ ntl@5.0.0 is out which ships a HUGE improvement over this problem, featuring a task cache that allow us not only to have the last ran task selected by default but also adds a handy nt
command that will automatically run the last task - so in theory you can just replace your usage of ntl
for nt
in order to get the history working as intended and whenever you want to change tasks, append the l
back at the end to run ntl
and select a different task