-
-
Save muendelezaji/c14722ab66b505a49861b8a74e52b274 to your computer and use it in GitHub Desktop.
Convert Bash history to Zsh history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# This is how I used it: | |
# $ cat ~/.bash_history | python bash-to-zsh-hist.py >> ~/.zsh_history | |
import sys | |
import time | |
def main(): | |
timestamp = None | |
for line in sys.stdin.readlines(): | |
line = line.rstrip('\n') | |
if line.startswith('#') and timestamp is None: | |
t = line[1:] | |
if t.isdigit(): | |
timestamp = t | |
continue | |
else: | |
sys.stdout.write(': %s:0;%s\n' % (timestamp or time.time(), line)) | |
timestamp = None | |
if __name__ == '__main__': | |
main() |
Works fine in Linux Mint Debian Edition 5 (LMDE 5). Thank you.
Works fine on RockyLinux 9 (Workstation) with zsh 5.8, ohmyzsh and python3.9.10.
Many thx. Great timesaver!
Merci!
if zsh_history format is
: 1670471184:0;cat ~/.zsh_history
need use int(time.time()) at line 21
Thanks!
Thanks
gracias!!!
Worked for me, thanks.
Thanks!!! Helped a lot!
Worked like a charm !! Thank you 👍
Wondering why zsh framework doesn't have a feature to import the bash history as part of initial setup. 🤔
Thank you!!
Thanks!
Worked perfectly. Thanks
If you have UnicodeEncodeError
:
lines = []
with open("/home/mmatrosov/.bash_history", "rb") as f:
while bytes := f.readline():
lines.append(bytes.decode("ascii", "backslashreplace"))
hero of my day
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works fine in Ubuntu 22.04, thanks for it!