Skip to content

Instantly share code, notes, and snippets.

@itsdonnix
Forked from muendelezaji/bash-to-zsh-hist.py
Created October 29, 2024 02:43
Show Gist options
  • Save itsdonnix/06ba181564bdc25e326fce7081a97ad6 to your computer and use it in GitHub Desktop.
Save itsdonnix/06ba181564bdc25e326fce7081a97ad6 to your computer and use it in GitHub Desktop.
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()
@itsdonnix
Copy link
Author

itsdonnix commented Oct 29, 2024

Handy one liner to exec it:

cat ~/.bash_history | curl -s https://gist.githubusercontent.com/itsdonnix/06ba181564bdc25e326fce7081a97ad6/raw/49f0fb7f661bdf794742257f58950d209dd6cb62/bash-to-zsh-hist.py | python >> ~/.zsh_history

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