Git Product home page Git Product logo

zsh_history's Introduction

Thanks to jcsalterego for the idea and who's already implemented the same thing for bash

Backup and Restore ZSH history

  • Simple python script that can backup and restore your zsh history file to a sqlite db
  • Dedups commands, and prepends any commands that were in the db but not in the history file
  • Accepts a max length parameter
    • This does not truncate your existing file
    • If max length is <= than the size of your existing file, no new commands will be added to your history file
    • Otherwise, it will pull commands based on their timestamps until max length is reached

Running it

usage: ./src/hist.py [-h] [-p PATH] [-d DBNAME] [-m MAXLINES] [-b] [-r]

Backup/Restore zsh history

optional arguments:
  -h, --help               show this help message and exit
  -p PATH,      --path     PATH  path to ZSH history    (default $HOME/.zsh_history)
  -d DBNAME,    --dbname   DBNAME SQLite db path        (default $HOME/.zsh_hist_backup.db)
  -m MAXLINES,  --maxlines MAXLINES max size of history file (default no limit)
  -b, --backup
  -r, --restore

Backup:

./src/hist.py -b

Restore:

./src/hist.py -r

Restoring history every time you open a shell

  • Just add the restore command to your ~/.zshrc file! (with the path from $HOME of course)

Backing up your DB

  • I've scheduled a launchd task on my mac to push my db to git every evening. Here's a link to the scripts

Feedback and comments welcome!

zsh_history's People

Contributors

m1xzg avatar rohancme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

zsh_history's Issues

Does not handle multiple line commands?

I had high hopes for this tool and spent some time pulling all the histories I could find from years of backup drives. I consider the command history to be the best kind of documentation queuing my mind to any stackoverflow answers or blog posts online with good solutions to problems... always first testing out the solution on the zsh (even python, or awk, or jq, or whatever else).
However, with said workflow I OFTEN have multi-line commands.

I ran the backup from all these files then I tried a restore on a test file and it seems like all commands are truncated to a single line. This is not particularly useful as I can't trust the restoration. Am I doing something wrong or is the design indeed only intended for single line commands?

I am considering implementing a fix, although initially I was gonna write something in awk. Perhaps a regex search to identify full commands might work in python instead of parsing lines 1 by 1.

Please let me know what you think.

sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory...

Thank you for this, it looks like exactly what I want. However, trying to run it, I got an exception right off the bat. Is it obvious what the problem is? I might try to fix it myself but am not yet familiar with the code.

[patkujawa@LS2-00159 Mon Dec 10 10:56:41 MST 2018] ~/oss/zsh_history (master)
❯ python2 ./src/hist.py -b                                                                                                                                                      ⏎
Traceback (most recent call last):
  File "./src/hist.py", line 121, in <module>
    backup(args.path, args.dbname)
  File "./src/hist.py", line 59, in backup
    u" VALUES(?,?,?)", rows)
sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.