Skip to content

Instantly share code, notes, and snippets.

@dhensen
Created December 7, 2018 23:39
Show Gist options
  • Save dhensen/64a5d3a93a499bd75df2f62ef014865c to your computer and use it in GitHub Desktop.
Save dhensen/64a5d3a93a499bd75df2f62ef014865c to your computer and use it in GitHub Desktop.
Convert Bash history to zsh history
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Usage:
# $ cat ~/.bash_history | ./bash-history-to-zsh-history.py >> ~/.zsh_history
import sys
import time
def main():
# this thing is ineffecient because the whole thing is read into memory just to count lines
# only use for small-ish file sizes
lines = sys.stdin.readlines()
linecount = len(lines)
timestamp = time.time() - linecount
for line in lines:
timestamp += 1
line = line.rstrip('\n')
sys.stdout.write(': %s:0;%s\n' % (timestamp, line))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment