Last active
June 27, 2019 20:36
-
-
Save gdebenito/3923b09494f15ba59e139a25ff9f0cc6 to your computer and use it in GitHub Desktop.
bash_history efficent cleaner
This file contains hidden or 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 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