Skip to content

Instantly share code, notes, and snippets.

@nad2000
Created September 5, 2017 07:24
Show Gist options
  • Save nad2000/2ca76b1b55cb796671da5da8a34f6032 to your computer and use it in GitHub Desktop.
Save nad2000/2ca76b1b55cb796671da5da8a34f6032 to your computer and use it in GitHub Desktop.
migrate bash history to zsh...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
HOME = os.path.join(home = expanduser("~")
import sys, os
def main():
bash_history = open(os.path.join(HOME, ".bash_history"), 'r')
zsh_history = open(os.path.join(HOME, ".zsh_history"), 'a')
timestamp = None
for line in bash_history.readlines():
line = line.rstrip('\n')
if line.startswith('#') and timestamp is None:
t = line[1:]
if t.isdigit():
timestamp = t
continue
elif timestamp:
zsh_history.write(': %s:0;%s\n' % (timestamp, line))
timestamp = None
close(zsh_history)
close(bash_history)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment