Atuin is wonderful for being able to select a single command from history, but I find myself wanting to compose multiple commands (similarly to fc -e $EDITOR -200 -1
or redo ). Roughly, I would like to concatenate commands on newlines, optionally with &&
or |
. A quick example of the functionality I’m looking for is below, but I believe that Atuin could further improve on this (e.g., deleting commands).
function _build_interactive_history_widget {
local tempfile
tempfile=$(mktemp --tmpdir history.tmpXXXXX)
atuin history list --print0 --cmd-only | uniq --zero-terminated |\
fzf --read0 --multi \
--query "${BUFFER}" \
--tac \
--preview "bat --language sh --style=plain ${tempfile}" \
--preview-window 'right,50%' \
--pointer='→' \
--header=$'TAB: cmd, SHIFT-TAB: cmd &&\nCTRL-p: cmd |, ENTER: accept\nCTRL-c to cancel' \
--bind "enter:abort" --height '100%' \
--bind "ctrl-c:execute-silent(truncate --size 0 ${tempfile})+abort" \
--bind "tab:execute-silent(echo {} >> ${tempfile})+refresh-preview" \
--bind "shift-tab:execute-silent(echo '{} && \\' >> ${tempfile})+refresh-preview" \
--bind "ctrl-p:execute-silent(echo '{} |\\' >> ${tempfile})+refresh-preview" \
>/dev/null
[[ -s "${tempfile}" ]] && LBUFFER="$(cat "${tempfile}")"
}