Skip to content

Instantly share code, notes, and snippets.

@christopherstott
Created January 23, 2016 23:39
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save christopherstott/59a5e36b8d2f3f015bb7 to your computer and use it in GitHub Desktop.
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');
@christopherstott
Copy link
Author

npm install expand-home-dir before running

@felipefdl
Copy link

Works well!

@simonmeusel
Copy link

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

@hnykda
Copy link

hnykda commented Feb 21, 2018

Instead of trying to find out how npm works, I put something together in Python.

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