mitnk / cicada

An old-school bash-like Unix shell written in Rust
https://hugo.wang/cicada/
MIT License
981 stars 50 forks source link

Optionally import Bash history into sqlite database on first run #28

Closed rypervenche closed 3 years ago

rypervenche commented 4 years ago

It would be nice if, upon first run (i.e., the cicada history database does not yet exist), the user could be prompted to import their Bash history into the database. If no date exists for an entry then it would use the current timestamp, otherwise it would use the provided timestamp from the .bash_history file:

Example .bash_history with timestamps

#1603194812
startx
#1603195328
vim .inputrc
mitnk commented 4 years ago

This is a good user requirement, but I don't want to add it as a cicada feature. Because there are more shells, bash, fish, zsh, xonsh etc, they all have different history layouts.

However, I think we can add a cicada builtin or something to export a way to import history items. And draft a section in the manual to guide users how to import.

mitnk commented 4 years ago

Just added a new command history add to the builtin history in v0.9.13. Now you can load bash history with a script like this:

#!/usr/local/bin/cicada
for x in $(sed 's/ /UNIQ_TOKEN_CICADA_SPACE/g' ~/.bash_history)
    history add "$(echo ${x} | sed 's/UNIQ_TOKEN_CICADA_SPACE/ /g')" -t $(date +"%s")
done

Save above content to foo.sh and run it with cicada foo.sh will do the work.

If you have bash available, you can use the bash way:

#!/bin/bash
while IFS= read -r line; do
    cicada -c "history add "${line}""
done < ~/.bash_history

(NOT fully tested these scripts)

Happy hacking!