Hello, I usually run the same command with async-shell-command, however I have to navigate back to the last command history to trigger my last run command, is there any way async-shell-command (and shell-command) can autofill with last run command so that I just hit enter without extra steps?
I tweaked the answer somewhat, as it bothered me that we were getting the most recent command inserted and having it show up again when you decide to go back to an earlier command. In other words, with the OP’s advice, we get the most recent command in the minibuffer history twice, once auto-filled and once in the regular history.
I’m sure there are cleaner ways to do it than using a custom global variable no other functions know about, which could I think lead to some weird side effects at some point… but for now, I like the behavior:
Let me know if anyone has improvements/objections!
I saw your final version on your config, just a small question, what does
'(shell-command-history . 1)
means? If I understand it correctly, it returns a new list without the last 1 item from the original list, however I tried to evaluate it on emacs but it does not return the value.Yeah, that one took some digging! I found the relevant bit in the Elisp manual. I should have some elisp for you to access the area of the manual within Emacs but I’m not there yet. : ) Here’s the HTML version.
That bit of a code is a cons pair, a list of the symbol
shell-command-history
and the number 1. The history argument tocompleting-read
(and therefore by extensionread-shell-command
) can take in either a symbol for a history variable or a cons pair of a history variable symbol and an index to start with.