not-poma / lazyshell

GPT powered Zsh completion script
MIT License
370 stars 26 forks source link

Save query history in $HISTFILE.lazyshell-complete #8

Open xPMo opened 1 year ago

xPMo commented 1 year ago

Additionally, exit out without querying or saving history if query was empty. ChatGPT has typically responded with something like "please submit a query".

not-poma commented 1 year ago

I think merging history saving makes sense when the script can actually fetch the past queries on up/down keys.

Empty response change is a good idea, can be merged immediately if you submit it in a separate PR.

xPMo commented 1 year ago

I think merging history saving makes sense when the script can actually fetch the past queries on up/down keys.

Unless I'm misunderstanding you, that's exactly what I've implemented here. read-from-minibuffer uses zle recursive-edit under the hood, which can go up and down through history. By first fc -ap, we load a new history file such as ~/.zsh_history.lazyshell-complete which read-from-minibuffer can scroll through, and ask zsh to unload it when the function exits. If the user entered a query, print -sr adds it to the current history file.

Empty response change

I've actually played around with a few things in my fork, and realized there is value in allowing an empty buffer to trigger a request. Here's what I put together over there: