Skip to content

Instantly share code, notes, and snippets.

@gdebenito
Last active June 27, 2019 20:36
Show Gist options
  • Save gdebenito/3923b09494f15ba59e139a25ff9f0cc6 to your computer and use it in GitHub Desktop.
Save gdebenito/3923b09494f15ba59e139a25ff9f0cc6 to your computer and use it in GitHub Desktop.
bash_history efficent cleaner
'use-strict'
const process = require('process')
const fs = require('fs')
const filename = process.argv.slice(process.argv.length - 1, process.argv.length)[0]
const data = fs.readFileSync(filename, { encoding: 'utf-8' })
const lines = data.split('\n').map((line) => line.trim())
let dataWant = []
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (!line.startsWith('cd ') &&
!line.startsWith('cat ') &&
!line.startsWith('#') &&
!line.startsWith('rm ') &&
!line.startsWith('vi') &&
!line.startsWith('sed ') &&
!line.startsWith('kill ') &&
!line.startsWith('git commit ') &&
!line.startsWith('chmod ') &&
!line.includes('downloadVideo') &&
!line.startsWith('git add ') &&
!line.startsWith('git st') &&
!line.startsWith('git rm') &&
!line.startsWith('git br')
) {
dataWant.push(line);
}
}
const set = new Set(dataWant)
const output = Array.from(set).sort().join('\n')
fs.writeFileSync(filename, output, { encoding: 'utf-8' })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment