Skip to content

Instantly share code, notes, and snippets.

@yarda7
Forked from muendelezaji/bash-to-zsh-hist.py
Last active December 22, 2023 11:17
Show Gist options
  • Save yarda7/3ddc1fc2f768b0d008e49d534e936ed4 to your computer and use it in GitHub Desktop.
Save yarda7/3ddc1fc2f768b0d008e49d534e936ed4 to your computer and use it in GitHub Desktop.
Convert Bash history to Zsh history
#!/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
sys.stdin.reconfigure(encoding='latin-1')
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()
@yarda7
Copy link
Author

yarda7 commented Dec 22, 2023

Avoid UnicodeDecodeError: 'utf-8' codec can't decode byte

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment