Skip to content

Instantly share code, notes, and snippets.

@mzpwr
Forked from muendelezaji/bash-to-zsh-hist.py
Last active January 12, 2023 15:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzpwr/d0104cb67b37394c80de1dd3182a609a to your computer and use it in GitHub Desktop.
Save mzpwr/d0104cb67b37394c80de1dd3182a609a 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:
# $ strings ~/.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('\r\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 int(time.time()), line))
timestamp = None
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment