I’ve seen a few mentions of this — when using the bash built-in “fc” Atuin doesn’t record the command that has been edited, but just the “fc” command itself.
However, if I do something like this:
alias fc='fc; fc -ln -1 > /tmp/lastcmd.txt'
then the full, edited version of the last command appears in /tmp/lastcmd.txt (and I get to use “fc”). Is there a way to feed the output of “fc -ln -1” into Atuin’s history?
My other thought was that there may be a way to use the precmd section in bash-preexec.sh to handle the situation, but I haven’t messed around with that much at this stage (I’m only onto my second day of using Atuin).
I’ve added this to the end of my .bashrc and it seems to do what I wanted (I also added “^fc” to the history_filter) — so it lets me edit the last command and run it, and adds that command to my Atuin history:
fc () {
# Replace the builtin fc with some pre-processing
echo "$(builtin fc -ln -1)"|sed 's/^[ \t]*//' > /tmp/fc$$
vi /tmp/fc$$
IFS=$'\n'
lastcmd="$(cat /tmp/fc$$)"
for line in $lastcmd;
do
echo -e "\011\033[38;5;240m${line}\033[00m";
eval "$line";
done
lastexit=$?
histid=$(atuin history start "$(echo $lastcmd)")
atuin history end --exit $lastexit $histid
}
There are almost certainly more elegant ways to achieve this, so I’m open to any comments/suggestions!