pawamoy / shell-history

Visualize your shell usage with Highcharts!
ISC License
110 stars 2 forks source link

Use CSV formatting instead of custom colon-separated + base64 encoded #26

Open pawamoy opened 5 years ago

pawamoy commented 5 years ago

The idea is to make the history file more readable for humans, but also easily importable by other tools.

I don't think there's a library for handling CSV files in Bash, and even if there was, I think it would slow down things a lot, which we don't want because shellhistory happens in interactive shells and we cannot let users wait for more than 200ms between each command. Appending a line to the history file must be as fast as possible.

But the CSV formatting is not hard either, so we could do it by hand. If I remember correctly, you can use any delimiter you want, as long as fields that contain it are enclosed in double-quotes. If these same fields also contain double-quotes, then you must simply double these.

Example with a comma as delimiter:

field 1,,field 3,"hey, I'm field 4!",,"he said ""4""? alright, then I'm gonna say ""6""!",field 7

Same string imported in GNumeric:

Screenshot_2019-05-01_15-58-35

It's working, yay!

So instead of encoding parents and working directory in base 64, we could simply enclose them in double-quotes, and use some sed 's/"/""/g on it. And instead of prepending a colon on normal lines, and a semi-colon on extra command lines, we could also simply do the same for the command.

:...:echo "a
;b
;c" | wc -c

would become

...:"echo ""a
b
c"" | wc -c"

Also, just to make sure, we could also enclose hostname and user in double-quotes.