atuinsh / atuin

✨ Magical shell history
https://atuin.sh
MIT License
19.67k stars 538 forks source link

multiline commands in Zsh history get corrupted after import #1555

Open oconnor663 opened 7 months ago

oconnor663 commented 7 months ago

I had this command in my Zsh history:

for i in *.xml ; do ;
    echo "=== $i ==="
    if ! ./parse.py "$i" ; then
        break
    fi
done

I then ran atuin import zsh and put eval "$(atuin init zsh)" in my .zshrc. Now when I ctrl-R and pull up that command, it looks like this:

for i in *.xml ; do ;\
    echo "=== $i ==="\
    if ! ./parse.py "$i" ; then\
        break\
    fi\
done
zsh: parse error near `then'

It looks like some backslashes are getting inserted into the command that shouldn't be there. Some sort of escaping bug?

conradludgate commented 7 months ago

(first, thanks for your work on BLAKE3)

It's possible that zsh inserted the backslashes into the history to make it clear that they are a single multiline command and not many single line commands. I need to double check the code/zsh histfile.

In general, bash/zsh/fish histfiles are full of ambiguous/weird cases. Why couldn't they just use jsonlines...

lilydjwg commented 7 months ago

I don't have this issue because zsh rewrites my multiline commands into one line in the history but I do remember this kind of issue happened to me somewhere (not atuin) in the past.

Why couldn't they just use jsonlines...

Because JSON was born too late :-)

danielfleischer commented 1 month ago

Solution in #98 helped, but this needs to be addressed in the zsh import code.