Skip to content

Instantly share code, notes, and snippets.

@nico-zck
Forked from op/bash-history-to-zsh-history.py
Last active March 10, 2021 08:15
Show Gist options
  • Save nico-zck/fa9e403a6454620374d5ccc1ab38c98c to your computer and use it in GitHub Desktop.
Save nico-zck/fa9e403a6454620374d5ccc1ab38c98c to your computer and use it in GitHub Desktop.
Bash history to Zsh history
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''simply copy to python command line and press enter.'''
import time
from os.path import expanduser
timestamp = None
with open(expanduser("~/.bash_history"), "r") as f:
bash = f.readlines()
zsh = []
for line in bash:
line = line.rstrip("\n")
if line.startswith("#") and timestamp is None:
t = line[1:]
if t.isdigit():
timestamp = t
continue
else:
zsh.append(": %s:0;%s\n" % (timestamp or time.time(), line))
timestamp = None
with open(expanduser("~/.zsh_history"), "a") as f:
f.writelines(zsh)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment