Skip to content

Instantly share code, notes, and snippets.

@lapo-luchini
Created October 8, 2024 20:20
Show Gist options
  • Save lapo-luchini/3b5e2b5d42326393a6ba5ba6b5216d08 to your computer and use it in GitHub Desktop.
Save lapo-luchini/3b5e2b5d42326393a6ba5ba6b5216d08 to your computer and use it in GitHub Desktop.
Sort extended ZSH history (works with multi-line entries)
#! /usr/bin/env node
const fs = require('fs');
const lines = fs.readFileSync(process.argv[2], 'utf8').split(/(?<=[^\\])\n/);
lines.sort((a, b) => a.split(/:/)[1] - b.split(/:/)[1]);
fs.writeFileSync(process.argv[2], lines.join('\n'), 'utf8');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment