-
Notifications
You must be signed in to change notification settings - Fork 0
/
fish-history-clean.js
43 lines (38 loc) · 969 Bytes
/
fish-history-clean.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// extract commands that is sort of useful for migration purposes.
const fs = require('fs');
const h = fs.readFileSync('./fish_history', 'utf-8').split('\n');
const rs = [];
const cmdPrefix = '- cmd: '
const blackList = [
`${cmdPrefix}git`,
`${cmdPrefix}z `,
`${cmdPrefix}ls`,
`${cmdPrefix}ag `,
];
const whiteList = [
`${cmdPrefix}avenue `,
`${cmdPrefix}onecloud `,
`${cmdPrefix}curl `,
`${cmdPrefix}aws `,
`${cmdPrefix}system_profiler `,
`${cmdPrefix}openssl `,
`${cmdPrefix}docker `,
`${cmdPrefix}k6 `,
`${cmdPrefix}java `,
`${cmdPrefix}ssh `,
]
let includeRow = false;
for(const l of h){
if(l.startsWith(cmdPrefix)){
// includeRow = !isBadStart(l);
includeRow = isGoodStart(l);
}
includeRow && rs.push(l);
}
fs.writeFileSync('output', rs.join('\n'));
function isBadStart(line){
return blackList.some(pre => line.startsWith(pre));
}
function isGoodStart(line){
return whiteList.some(pre => line.startsWith(pre));
}