Skip to content

Instantly share code, notes, and snippets.

@RoryDungan
Created June 12, 2018 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoryDungan/177360ba5592546400c7526971e7af88 to your computer and use it in GitHub Desktop.
Save RoryDungan/177360ba5592546400c7526971e7af88 to your computer and use it in GitHub Desktop.
Work out which commands I use in Fish the most
'use strict'
const fs = require('fs')
const path = require('path')
const os = require('os')
const df = require('data-forge')
// Read the history of commands executed in the Fish shell and work out which
// are used the most!
const filePath = path.join(os.homedir(), '.local/share/fish/fish_history')
const historyFile = fs.readFileSync(filePath)
// Entries in the Fish shell history are stored in the following format:
// - cmd: git add package-lock.json
// when: 1527650946
// paths:
// - package-lock.json
// We only care about the initial part of the command here
const cmdRegex = /^- cmd: ([a-z_\-0-9]+).*$/i
new df.DataFrame(historyFile.toString().split('\n'))
.where(line => cmdRegex.test(line))
.select(line => cmdRegex.exec(line)[1])
.groupBy(cmd => cmd)
.select(group => ({ name: group.first(), count: group.count() }))
.orderByDescending(cmd => cmd.count)
.forEach(cmd => {
console.log(cmd.name + ': ' + cmd.count)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment