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 fernandoacorreia commented Sep 5, 2017

Worked well for me on Ubuntu 16.04. Thanks.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jul 4, 2018

Like a charm on Ubuntu 17.10 too!

@sepehrmm

This comment has been minimized.

Copy link

@sepehrmm sepehrmm commented Dec 26, 2018

worked on Ubuntu 14.04, Thanks.

@majidalavizadeh

This comment has been minimized.

Copy link

@majidalavizadeh majidalavizadeh commented Feb 13, 2019

Worked like a charm on Mac

@brnl

This comment has been minimized.

Copy link

@brnl 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 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 BeebBenjamin commented Sep 20, 2019

Works for me on Ubutnu 18.04!

@awthwathje

This comment has been minimized.

Copy link

@awthwathje awthwathje commented Nov 8, 2019

Debian Buster, works good.

@michaelklos

This comment has been minimized.

Copy link

@michaelklos michaelklos commented Dec 29, 2019

Worked like a charm (Ubuntu 18.04). Thanks!

@fbraz3

This comment has been minimized.

Copy link

@fbraz3 fbraz3 commented Mar 11, 2020

OSX Catalina, works fine! =D
Python 2.7.16

@fahimio

This comment has been minimized.

Copy link

@fahimio fahimio commented May 8, 2020

Nice!! Worked beautifully!

@Kl0ven

This comment has been minimized.

Copy link

@Kl0ven Kl0ven commented Jun 18, 2020

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

@dexios1

This comment has been minimized.

Copy link

@dexios1 dexios1 commented Jul 27, 2020

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

@ahmedhr

This comment has been minimized.

Copy link

@ahmedhr ahmedhr commented Oct 6, 2020

Works!!

@mc256

This comment has been minimized.

Copy link

@mc256 mc256 commented Dec 10, 2020

awesome!

@evanjt

This comment has been minimized.

Copy link

@evanjt evanjt commented Feb 8, 2021

Great, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment