Created
June 12, 2018 09:59
-
-
Save RoryDungan/177360ba5592546400c7526971e7af88 to your computer and use it in GitHub Desktop.
Work out which commands I use in Fish the most
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 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