joerdav / xc

Markdown defined task runner.
https://xcfile.dev/
MIT License
1.04k stars 25 forks source link

feature: add executed task to shell history #114

Open a-h opened 4 months ago

a-h commented 4 months ago

I'm enjoying using the interactive mode. One thing I've noticed, is that I'll often run xc, select docker-build and it will start.

Then I'll make some changes, and want to run it again, so I'll press the up arrow on the keyboard, or I'll use Ctrl+R to search, but docker-build is not in the history.

I think it would be a case of adding a line to either .zsh_history if the shell is zsh, or .bash_history is the shell is bash.

I can put a PR for that together if you like.

joerdav commented 4 months ago

I noted this as a thing that was frustrating me too, would happily take a PR!

jdmcgrath commented 3 months ago

Hi both @joerdav @a-h.

I had a look at this, and couldn't get it to work. I am not sure about bash, but for zsh it is perfectly possible to add to .zsh_history, though the changes to the file are not checked until after the next run of a script. I noticed you can have a script as follows which refreshes the zsh history if in a terminal session directly:

#!/bin/zsh
fc -R

though if run through the Go Script, the effect of this is confined to the subprocess created by exec.Command, not the parent shell session. Please see commit here for crude concept and to check out the issue I'm running into.

joerdav commented 1 month ago

I can see the problem here, might need some more thinking!

I've had some inspiration on this which might solve the problem by changing how it works.

We could have the xc command pre populate your commandline. It'll mean pressing enter twice but would have the side effect of the terminal handling history?

Is this too annoying of a change?

I've been using https://github.com/atuinsh/atuin for a while and it also pre-populates your cli with a command rather than running it for you.

a-h commented 1 month ago

That would be great for me!

joerdav commented 1 month ago

I looked further and the way this works in atuin is that its a zsh/bash/fish plugin, that communicates to the cli.

So its able to do things like refresh the history or prepopulate the commandline as there are hooks in dotfiles. The atuin command on its own isn't able to do any of these things on its own :(

So back at square one with @jdmcgrath , you observation that this can't be done from the xc command are correct. It would be a larger change including authoring plugins for zsh/bash/fish

phanirithvij commented 1 month ago

navi does the same, user needs to source navi widget <shell> in bashrc/zshrc/config.fish, from what I can read it uses READLINE_POINT and READLINE_LINE to set to shell history.

Also on a side note, I am on nixos and use home-manager to configure bash/fish etc. and xc -complete tries to write to bashrc which is read-only for me. so an xc hook <shell> which prints the corresponding script would be very much appreciated. (like zoxide, starship, direnv, fzf and many other tools provide)