Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh generates invalid UTF-8 encoding in the history



On Oct 5,  2:41pm, Mikael Magnusson wrote:
}
} History entries are written in metafied form to the history file. You
} can use the 'history' command to print a readable version of history,
} or use this small utility http://mika.l3ib.org/code/unmetafy.c

Nice little utility, but it doesn't handle converting "\\\n" into "\n".
Maybe that's not desirable anyway, as the downstream utility might
want to do that itself.

To unmetafy with the shell (including backslash-newline processing):

    () { fc -pa $HISTFILE $SAVEHIST && fc -rnl -1 1 }

Or more generically

    unmetafy() {
      () { fc -pa $1 ${$(wc -l $1)[1]} && fc -rnl -1 1 } ${1:-=(cat)}
    }

Vincent might also consider using a zshaddhistory hook to maintain a copy
of the history file that is unmetafied and stripped of extended-history
markup, though that gets a bit more complicated.



Messages sorted by: Reverse Date, Date, Thread, Author