Skip to content

Instantly share code, notes, and snippets.

Last active August 12, 2023 01:41
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save marchrius/71f858c2b032f037d286cbf2394ad8a7 to your computer and use it in GitHub Desktop.
const fs = require('fs');
* This script transfers bash history to zsh history
* Change bash and zsh history files, if you don't use defaults
* Usage: node bash_to_zsh_history.js
* Author: Matteo Gaggiano
// change if you don't use default values
const BashHistoryFilePath = process.env.HOME + "/.bash_history";
const ZshHistoryFilePath = process.env.HOME + "/.zsh_history";
// Read the bash history file
const bashHistFile = fs.readFileSync(BashHistoryFilePath, 'utf8');
const bashHistFileLines = bashHistFile.split("\n");
// Open the zsh history file
const zshHistFileLines = [];
// Get timestamp required for zsh history file format and update the history file
let time = ( / 1000).toFixed(0) * 1;
bashHistFileLines.forEach((command, index) => {
time += 1;
if (command && command.trim().length > 0)
zshHistFileLines.push(`: ${time}:0;${command}\n`);
fs.writeFileSync(ZshHistoryFilePath, zshHistFileLines.join(''), {encoding: 'utf8', flag: 'a+'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment