Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Import ZSH history to Fish
'use strict';
const fs = require('fs');
const expandHomeDir = require('expand-home-dir');
const zshHistoryRaw = fs.readFileSync(expandHomeDir('~/.zsh_history'), 'utf8');
const zshHistoryLines = zshHistoryRaw.split('\n');
const transformLine = line => {
try {
const semicolonIndex = line.indexOf(';');
const command = line.substring(semicolonIndex + 1);
const when = line.substring(0, semicolonIndex).split(':')[1].trim();
return `- cmd: ${command}\n when: ${when}`;
} catch (e) {
// Probably a continuation of the previous line.
// I don't care about these
}
};
const fishHistory = zshHistoryLines.map(line => transformLine(line)).join('\n');
fs.writeFileSync(expandHomeDir('~/.config/fish/fish_history'), fishHistory, 'utf8');
Owner

christopherstott commented Jan 23, 2016

npm install expand-home-dir before running

Works well!

Works! You should maybe create the file if it does not exists :)

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