-
Notifications
You must be signed in to change notification settings - Fork 6
/
what-am-i-using.mjs
executable file
·123 lines (98 loc) · 3.22 KB
/
what-am-i-using.mjs
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/node
/**
* This script services as a quick way to show what I use.
* The output isn't the prettiest, but it's good enough.
*/
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
const ROOT = path.dirname(fileURLToPath(import.meta.url));
async function shellUtilities() {
heading('Shell Utilities');
let install = await getFile('./install.sh');
let lines = install.split('\n');
let apt = splitOnSpace(lines
.filter(line => line.includes('apt install'))
.map(line => line.replace('sudo apt install', ''))
);
let snap = splitOnSpace(lines
.filter(line => line.includes('snap install'))
.map(line => line.replace('sudo snap install', ''))
);
let python = splitOnSpace(lines
.filter(line => line.includes('pip install') || line.includes('pip3 install'))
.map(line => line.replace(/pip3? install( --user)?/, ''))
);
console.log({
'apt packages': apt,
'snap packages': snap,
'python packages': python
});
}
async function vimPlugins() {
heading('neovim plugins');
let pluginDir = path.join(ROOT, 'home', '.config', 'nvim', 'lua', 'plugins');
let files = await fs.readdir(pluginDir);
function getPluginNames(file) {
let singleLine = (quote) => {
return new RegExp(`use ${quote}([^${quote}]+)${quote}`, 'gm');
};
let singleLineWithBracket = (quote) => {
return new RegExp(`use \{ ${quote}([^${quote}]+)${quote}`, 'gm');
}
let multiLine = (quote = `'`) => {
return new RegExp(`^\\s*${quote}([^${quote}]+)${quote}\\s*,?$`, 'gm');
};
let matches = [
...file.matchAll(multiLine(`'`)),
...file.matchAll(multiLine(`"`)),
...file.matchAll(singleLine(`"`)),
...file.matchAll(singleLine(`'`)),
...file.matchAll(singleLineWithBracket(`'`)),
...file.matchAll(singleLineWithBracket(`'`)),
]
.map(match => match[1])
.filter(Boolean)
.filter(match => match.includes('/'))
.filter(match => match.replace(/\s\s/, ''))
.filter(match => !match.includes(' -- '))
.filter(match => !match.includes('~/'))
.filter(match => !match.startsWith('/'))
.filter(match => !match.startsWith('https:'))
.filter(match => !match.startsWith('./'))
.filter(Boolean);
return matches;
}
for (let file of files) {
let buffer = await fs.readFile(path.join(pluginDir, file));
let fileData = buffer.toString();
let plugins = getPluginNames(fileData);
console.log(`>> ${file}`);
console.log(plugins);
}
// concat all files into one.
// because 'packer' is used, the ways in which packages are declared is uniform
}
function splitOnSpace(lines) {
return [...(new Set(lines
.map(line => line.replace('\\', ''))
.map(line => line.trim())
.map(line => line.split(' '))
.flat()
.filter(Boolean)
)).values()];
}
function heading(title) {
console.log('-------------------------------------------')
console.log(` ${title}`);
console.log('-------------------------------------------')
}
async function getFile(filePath) {
let buffer = await fs.readFile(path.join(ROOT, filePath));
return buffer.toString();
}
async function main() {
await shellUtilities();
await vimPlugins();
}
main();