Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
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()
@fernandoacorreia

This comment has been minimized.

Copy link

fernandoacorreia commented Sep 5, 2017

Worked well for me on Ubuntu 16.04. Thanks.

@ghost

This comment has been minimized.

Copy link

ghost commented Jul 4, 2018

Like a charm on Ubuntu 17.10 too!

@sepehrmm

This comment has been minimized.

Copy link

sepehrmm commented Dec 26, 2018

worked on Ubuntu 14.04, Thanks.

@majidalavizadeh

This comment has been minimized.

Copy link

majidalavizadeh commented Feb 13, 2019

Worked like a charm on Mac

@brnl

This comment has been minimized.

Copy link

brnl commented Mar 7, 2019

Just an update that this one works really well :)
Ubuntu 18.10

@dijotmathews

This comment has been minimized.

Copy link

dijotmathews commented Sep 12, 2019

works on ubuntu 19.04 python 2.7.16
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
zsh 5.5.1 (x86_64-ubuntu-linux-gnu)
thanks!!

@BeebBenjamin

This comment has been minimized.

Copy link

BeebBenjamin commented Sep 20, 2019

Works for me on Ubutnu 18.04!

@awthwathje

This comment has been minimized.

Copy link

awthwathje commented Nov 8, 2019

Debian Buster, works good.

@michaelklos

This comment has been minimized.

Copy link

michaelklos commented Dec 29, 2019

Worked like a charm (Ubuntu 18.04). Thanks!

@fbraz3

This comment has been minimized.

Copy link

fbraz3 commented Mar 11, 2020

OSX Catalina, works fine! =D
Python 2.7.16

@fahimio

This comment has been minimized.

Copy link

fahimio commented May 8, 2020

Nice!! Worked beautifully!

@Kl0ven

This comment has been minimized.

Copy link

Kl0ven commented Jun 18, 2020

Thanks !!!! worked on WSL - python3.8

@dexios1

This comment has been minimized.

Copy link

dexios1 commented Jul 27, 2020

You're awesome @muendelezaji. Thanks for this. Worked so well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.