my-custom-os-fetcher 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +115 -0
- package/package.json +28 -0
package/index.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const os = require("os");
|
|
4
|
+
const pc = require("picocolors");
|
|
5
|
+
const si = require("systeminformation");
|
|
6
|
+
const { execSync } = require("child_process");
|
|
7
|
+
|
|
8
|
+
async function renderFetch() {
|
|
9
|
+
const [cpuData, gpuData, osData] = await Promise.all([
|
|
10
|
+
si.cpu(),
|
|
11
|
+
si.graphics(),
|
|
12
|
+
si.osInfo(),
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
let osType = os.type();
|
|
16
|
+
if (osType === "Darwin") {
|
|
17
|
+
osType = "macOS";
|
|
18
|
+
} else if (osType === "Windows_NT") {
|
|
19
|
+
osType = "Windows";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const SECONDS_IN_A_WEEK = 60 * 60 * 24 * 7;
|
|
23
|
+
const upTimeInSeconds = os.uptime();
|
|
24
|
+
const hours = Math.floor(upTimeInSeconds / 3600);
|
|
25
|
+
const minutes = Math.floor((upTimeInSeconds % 3600) / 60);
|
|
26
|
+
const seconds = Math.floor(upTimeInSeconds % 60);
|
|
27
|
+
|
|
28
|
+
const usedMemory = ((os.totalmem() - os.freemem()) / 1e9).toFixed(2);
|
|
29
|
+
const totalMemory = (os.totalmem() / 1e9).toFixed(2);
|
|
30
|
+
const memoryUsagePercentage = ((usedMemory / totalMemory) * 100).toFixed(2);
|
|
31
|
+
|
|
32
|
+
const cpuName = `${cpuData.manufacturer} ${cpuData.brand}`;
|
|
33
|
+
const distroName = osData.distro;
|
|
34
|
+
|
|
35
|
+
// --- LÓGICA UNIVERSAL DE GPU ---
|
|
36
|
+
let gpuName = "Unknown GPU";
|
|
37
|
+
|
|
38
|
+
// 1. Tenta pegar a NVIDIA real primeiro (Funciona no Windows nativo, Linux nativo e WSL2)
|
|
39
|
+
try {
|
|
40
|
+
const smiOutput = execSync("nvidia-smi --query-gpu=name --format=csv,noheader", { encoding: "utf-8", stdio: "pipe" });
|
|
41
|
+
if (smiOutput) {
|
|
42
|
+
gpuName = smiOutput.trim().split('\n')[0]; // Pega a primeira placa se houver mais de uma
|
|
43
|
+
}
|
|
44
|
+
} catch (error) {
|
|
45
|
+
// 2. Se não for NVIDIA ou não tiver o nvidia-smi, tenta usar o systeminformation
|
|
46
|
+
if (gpuData.controllers.length > 0) {
|
|
47
|
+
// Tenta ignorar o driver genérico do WSL e pegar uma placa com nome real, se existir
|
|
48
|
+
const realGpu = gpuData.controllers.find(c => c.model && !c.model.toLowerCase().includes("basic render"));
|
|
49
|
+
|
|
50
|
+
if (realGpu) {
|
|
51
|
+
gpuName = realGpu.model || realGpu.vendor;
|
|
52
|
+
} else {
|
|
53
|
+
gpuName = gpuData.controllers[0].model || gpuData.controllers[0].vendor;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// 3. Fallback final para Linux nativo via lspci (Corrigido os erros de sintaxe)
|
|
57
|
+
else if (osType === 'Linux') {
|
|
58
|
+
try {
|
|
59
|
+
const lspciOutput = execSync('lspci | grep -iE "vga|3d|display"', { encoding: "utf-8", stdio: "pipe" });
|
|
60
|
+
if (lspciOutput) {
|
|
61
|
+
const splitOutput = lspciOutput.split(': ');
|
|
62
|
+
if (splitOutput.length > 1) {
|
|
63
|
+
gpuName = splitOutput[1].split('\n')[0].trim();
|
|
64
|
+
gpuName = gpuName.replace(/\s*\(.*?\)\s*/g, '');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} catch (lspciError) {
|
|
68
|
+
// Falhou silenciosamente, mantém "Unknown GPU"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// --- RENDERIZAÇÃO ---
|
|
74
|
+
const asciiArt = [
|
|
75
|
+
pc.blue(" ██████████████"),
|
|
76
|
+
pc.blue(" ███ "),
|
|
77
|
+
pc.blue(" ███ "),
|
|
78
|
+
pc.blue(" ███ "),
|
|
79
|
+
pc.blue(" ███ "),
|
|
80
|
+
pc.blue(" ███ "),
|
|
81
|
+
pc.blue(" ██████████████ "),
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
const systemInfo = [
|
|
85
|
+
`${pc.cyan(pc.bold("User"))}: ${pc.bold(os.userInfo().username)}@${pc.bold(pc.bold(os.hostname()))}`,
|
|
86
|
+
`${pc.cyan(pc.bold("OS"))}: ${osType} - ${distroName} ${os.arch()}`,
|
|
87
|
+
`${pc.cyan(pc.bold("Kernel"))}: ${os.release()}`,
|
|
88
|
+
`${pc.cyan(pc.bold("CPU"))}: ${cpuName} | ${os.cpus().length} Cores`,
|
|
89
|
+
`${pc.cyan(pc.bold("GPU"))}: ${gpuName}`,
|
|
90
|
+
`${pc.cyan(pc.bold("Memory"))}: ${usedMemory} GB / ${totalMemory} GB (${memoryUsagePercentage}%)`,
|
|
91
|
+
`${pc.cyan(pc.bold("Uptime"))}: ${hours}h ${minutes}m ${seconds}s`,
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
console.log("");
|
|
95
|
+
const maxLines = Math.max(asciiArt.length, systemInfo.length);
|
|
96
|
+
|
|
97
|
+
for (let i = 0; i < maxLines; i++) {
|
|
98
|
+
// Mantém o espaçamento exato para não quebrar o layout
|
|
99
|
+
const artLine = asciiArt[i] || " ";
|
|
100
|
+
const infoLine = systemInfo[i] || "";
|
|
101
|
+
console.log(`${artLine} ${infoLine}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
console.log("");
|
|
105
|
+
if (upTimeInSeconds > SECONDS_IN_A_WEEK) {
|
|
106
|
+
console.log(
|
|
107
|
+
`Your system has been up for more than a week! Consider restarting it for better performance. 🔥`,
|
|
108
|
+
);
|
|
109
|
+
} else {
|
|
110
|
+
console.log(`Your system uptime is within a week. Keep it up! 🚀`);
|
|
111
|
+
}
|
|
112
|
+
console.log("");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
renderFetch();
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-custom-os-fetcher",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A modern alternative to Neofetch, providing detailed system information in a visually appealing format, made with Node.Js",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"myfetch": "./index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node index.js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"cli",
|
|
14
|
+
"neofetch",
|
|
15
|
+
"system-info",
|
|
16
|
+
"terminal",
|
|
17
|
+
"os",
|
|
18
|
+
"linux",
|
|
19
|
+
"wsl"
|
|
20
|
+
],
|
|
21
|
+
"author": "Felipe Lima Nogueira",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"type": "commonjs",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"picocolors": "^1.1.1",
|
|
26
|
+
"systeminformation": "^5.31.5"
|
|
27
|
+
}
|
|
28
|
+
}
|