Forked from christopherstott/import_zsh_history_to_fish.js
Last active
February 6, 2018 14:24
-
-
Save asus4/61e01631ea5c19acc7e4489763e32624 to your computer and use it in GitHub Desktop.
Import ZSH history to Fish
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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('~/.local/share/fish/fish_history'), fishHistory, 'utf8'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The fish_history path changed.
~/.local/share/fish/fish_history
for 2.3.0 and laternpm install -D expand-home-dir
before run