tr200 2.0.0 → 2.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/WINDOWS/TR-200-MachineReport.ps1 +80 -11
- package/bin/tr200.js +193 -5
- package/machine_report.sh +43 -0
- package/package.json +1 -1
|
@@ -20,6 +20,58 @@
|
|
|
20
20
|
Tested : Windows PowerShell 5.1 and PowerShell 7+
|
|
21
21
|
#>
|
|
22
22
|
|
|
23
|
+
[CmdletBinding()]
|
|
24
|
+
param(
|
|
25
|
+
[Alias('h', '?')]
|
|
26
|
+
[switch]$Help,
|
|
27
|
+
|
|
28
|
+
[Alias('v')]
|
|
29
|
+
[switch]$Version,
|
|
30
|
+
|
|
31
|
+
[Parameter(ValueFromRemainingArguments = $true)]
|
|
32
|
+
[string[]]$RemainingArgs
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
$script:TR200Version = '2.0.1'
|
|
36
|
+
|
|
37
|
+
# Handle Unix-style --flags (PowerShell doesn't natively support double-dash)
|
|
38
|
+
if ($RemainingArgs) {
|
|
39
|
+
foreach ($arg in $RemainingArgs) {
|
|
40
|
+
if ($arg -eq '--help' -or $arg -eq '-help') { $Help = $true }
|
|
41
|
+
if ($arg -eq '--version' -or $arg -eq '-version') { $Version = $true }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function Show-TR200Help {
|
|
46
|
+
$helpText = @"
|
|
47
|
+
|
|
48
|
+
TR-200 Machine Report v$script:TR200Version
|
|
49
|
+
|
|
50
|
+
Usage: TR-200-MachineReport.ps1 [options]
|
|
51
|
+
report [options]
|
|
52
|
+
|
|
53
|
+
Displays system information in a formatted table with Unicode box-drawing.
|
|
54
|
+
|
|
55
|
+
Options:
|
|
56
|
+
--help, -h Show this help message
|
|
57
|
+
--version, -v Show version number
|
|
58
|
+
|
|
59
|
+
When installed via npm (tr200):
|
|
60
|
+
tr200 Run the machine report
|
|
61
|
+
tr200 --help Show help (includes install/uninstall options)
|
|
62
|
+
tr200 --install Set up auto-run on terminal startup
|
|
63
|
+
tr200 --uninstall Remove auto-run from shell startup
|
|
64
|
+
|
|
65
|
+
When installed via install_windows.ps1:
|
|
66
|
+
report Run the machine report (works in CMD and PowerShell)
|
|
67
|
+
uninstall Remove TR-200 Machine Report
|
|
68
|
+
|
|
69
|
+
More info: https://github.com/RealEmmettS/usgc-machine-report
|
|
70
|
+
|
|
71
|
+
"@
|
|
72
|
+
Write-Host $helpText
|
|
73
|
+
}
|
|
74
|
+
|
|
23
75
|
#region Encoding and box-drawing configuration
|
|
24
76
|
|
|
25
77
|
# Ensure UTF-8 output for proper box-drawing characters on Windows PowerShell 5.1
|
|
@@ -60,16 +112,20 @@ function New-TR200BarGraph {
|
|
|
60
112
|
[int] $Width
|
|
61
113
|
)
|
|
62
114
|
|
|
115
|
+
# Convert chars to strings for multiplication (PS 5.1 compatibility)
|
|
116
|
+
$barFilled = [string]$TR200Chars.BarFilled
|
|
117
|
+
$barEmpty = [string]$TR200Chars.BarEmpty
|
|
118
|
+
|
|
63
119
|
if ($Total -le 0) {
|
|
64
|
-
return ($
|
|
120
|
+
return ($barEmpty * [math]::Max($Width, 1))
|
|
65
121
|
}
|
|
66
122
|
|
|
67
123
|
$percent = [math]::Max([math]::Min(($Used / $Total) * 100.0, 100.0), 0.0)
|
|
68
124
|
$filledBars = [int]([math]::Round(($percent / 100.0) * $Width))
|
|
69
125
|
if ($filledBars -gt $Width) { $filledBars = $Width }
|
|
70
126
|
|
|
71
|
-
$filled = $
|
|
72
|
-
$empty = $
|
|
127
|
+
$filled = $barFilled * $filledBars
|
|
128
|
+
$empty = $barEmpty * ([math]::Max($Width,0) - $filledBars)
|
|
73
129
|
return "$filled$empty"
|
|
74
130
|
}
|
|
75
131
|
|
|
@@ -406,12 +462,17 @@ function Show-TR200Report {
|
|
|
406
462
|
# Total inner width of table (excluding outer borders)
|
|
407
463
|
$innerWidth = 2 + $labelWidth + 3 + $dataWidth + 2 # "│ <label> │ <value> │"
|
|
408
464
|
|
|
465
|
+
# Convert chars to strings for multiplication (PS 5.1 compatibility)
|
|
466
|
+
$hzLine = [string]$TR200Chars.Horizontal
|
|
467
|
+
$vtLine = [string]$TR200Chars.Vertical
|
|
468
|
+
$tDown = [string]$TR200Chars.TDown
|
|
469
|
+
|
|
409
470
|
# Helper to write the top header and borders
|
|
410
471
|
function Write-TR200TopHeader {
|
|
411
472
|
param()
|
|
412
|
-
$top = $TR200Chars.TopLeft + ($
|
|
473
|
+
$top = $TR200Chars.TopLeft + ($hzLine * ($innerWidth)) + $TR200Chars.TopRight
|
|
413
474
|
Write-Host $top
|
|
414
|
-
$mid = $TR200Chars.TRight + ($
|
|
475
|
+
$mid = $TR200Chars.TRight + ($tDown * ($innerWidth)) + $TR200Chars.TLeft
|
|
415
476
|
Write-Host $mid
|
|
416
477
|
}
|
|
417
478
|
|
|
@@ -427,7 +488,7 @@ function Show-TR200Report {
|
|
|
427
488
|
if ($i -eq ($labelWidth + 2)) {
|
|
428
489
|
$line += $mid
|
|
429
490
|
} else {
|
|
430
|
-
$line += $
|
|
491
|
+
$line += $hzLine
|
|
431
492
|
}
|
|
432
493
|
}
|
|
433
494
|
$line += $right
|
|
@@ -436,7 +497,7 @@ function Show-TR200Report {
|
|
|
436
497
|
|
|
437
498
|
function Write-TR200Footer {
|
|
438
499
|
param()
|
|
439
|
-
$bottom = $TR200Chars.BottomLeft + ($
|
|
500
|
+
$bottom = $TR200Chars.BottomLeft + ($hzLine * ($innerWidth)) + $TR200Chars.BottomRight
|
|
440
501
|
Write-Host $bottom
|
|
441
502
|
}
|
|
442
503
|
|
|
@@ -450,7 +511,9 @@ function Show-TR200Report {
|
|
|
450
511
|
$padding = $totalWidth - $text.Length
|
|
451
512
|
$leftPad = [int]([math]::Floor($padding / 2.0))
|
|
452
513
|
$rightPad = $padding - $leftPad
|
|
453
|
-
|
|
514
|
+
$leftSpace = ' ' * $leftPad
|
|
515
|
+
$rightSpace = ' ' * $rightPad
|
|
516
|
+
Write-Host ($vtLine + $leftSpace + $text + $rightSpace + $vtLine)
|
|
454
517
|
}
|
|
455
518
|
|
|
456
519
|
function Write-TR200Row {
|
|
@@ -476,7 +539,7 @@ function Show-TR200Report {
|
|
|
476
539
|
$val = $val.PadRight($dataWidth)
|
|
477
540
|
}
|
|
478
541
|
|
|
479
|
-
Write-Host (
|
|
542
|
+
Write-Host ($vtLine + ' ' + $lbl + ' ' + $vtLine + ' ' + $val + ' ' + $vtLine)
|
|
480
543
|
}
|
|
481
544
|
|
|
482
545
|
# Render table
|
|
@@ -501,11 +564,17 @@ function Show-TR200Report {
|
|
|
501
564
|
|
|
502
565
|
#endregion Rendering
|
|
503
566
|
|
|
504
|
-
# If the script is executed directly (not dot-sourced), show the report
|
|
567
|
+
# If the script is executed directly (not dot-sourced), handle args or show the report
|
|
505
568
|
try {
|
|
506
569
|
if ($MyInvocation.InvocationName -ne '.') {
|
|
507
570
|
# Only auto-run when invoked as a script, not when dot-sourced from a profile
|
|
508
|
-
|
|
571
|
+
if ($Help) {
|
|
572
|
+
Show-TR200Help
|
|
573
|
+
} elseif ($Version) {
|
|
574
|
+
Write-Host $script:TR200Version
|
|
575
|
+
} else {
|
|
576
|
+
Show-TR200Report
|
|
577
|
+
}
|
|
509
578
|
}
|
|
510
579
|
} catch {
|
|
511
580
|
Write-Error $_
|
package/bin/tr200.js
CHANGED
|
@@ -13,8 +13,180 @@
|
|
|
13
13
|
const { spawn } = require('child_process');
|
|
14
14
|
const path = require('path');
|
|
15
15
|
const fs = require('fs');
|
|
16
|
+
const os = require('os');
|
|
17
|
+
const readline = require('readline');
|
|
16
18
|
|
|
17
19
|
const isWindows = process.platform === 'win32';
|
|
20
|
+
const isMac = process.platform === 'darwin';
|
|
21
|
+
const homeDir = os.homedir();
|
|
22
|
+
|
|
23
|
+
// Config block markers for shell profiles
|
|
24
|
+
const CONFIG_MARKER = 'TR-200 Machine Report (npm)';
|
|
25
|
+
const UNIX_CONFIG = `
|
|
26
|
+
# ${CONFIG_MARKER} - auto-run
|
|
27
|
+
if command -v tr200 &> /dev/null; then
|
|
28
|
+
tr200
|
|
29
|
+
fi
|
|
30
|
+
`;
|
|
31
|
+
const PS_CONFIG = `
|
|
32
|
+
# ${CONFIG_MARKER} - auto-run
|
|
33
|
+
if (Get-Command tr200 -ErrorAction SilentlyContinue) {
|
|
34
|
+
tr200
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
// Shell profile paths
|
|
39
|
+
function getProfilePaths() {
|
|
40
|
+
if (isWindows) {
|
|
41
|
+
return [
|
|
42
|
+
path.join(homeDir, 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1'),
|
|
43
|
+
path.join(homeDir, 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1')
|
|
44
|
+
];
|
|
45
|
+
} else if (isMac) {
|
|
46
|
+
return [
|
|
47
|
+
path.join(homeDir, '.zshrc'),
|
|
48
|
+
path.join(homeDir, '.bash_profile')
|
|
49
|
+
];
|
|
50
|
+
} else {
|
|
51
|
+
// Linux/BSD
|
|
52
|
+
return [
|
|
53
|
+
path.join(homeDir, '.bashrc'),
|
|
54
|
+
path.join(homeDir, '.profile')
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Prompt user for confirmation
|
|
60
|
+
function askConfirmation(question) {
|
|
61
|
+
return new Promise((resolve) => {
|
|
62
|
+
const rl = readline.createInterface({
|
|
63
|
+
input: process.stdin,
|
|
64
|
+
output: process.stdout
|
|
65
|
+
});
|
|
66
|
+
rl.question(question, (answer) => {
|
|
67
|
+
rl.close();
|
|
68
|
+
resolve(answer.toLowerCase().startsWith('y'));
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Check if config already exists in file
|
|
74
|
+
function hasConfig(filePath) {
|
|
75
|
+
if (!fs.existsSync(filePath)) return false;
|
|
76
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
77
|
+
return content.includes(CONFIG_MARKER);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Install auto-run to shell profiles
|
|
81
|
+
async function installAutoRun() {
|
|
82
|
+
const profiles = getProfilePaths();
|
|
83
|
+
const configBlock = isWindows ? PS_CONFIG : UNIX_CONFIG;
|
|
84
|
+
|
|
85
|
+
console.log('\nTR-200 Machine Report - Install Auto-Run\n');
|
|
86
|
+
console.log('This will configure tr200 to run automatically when you open a terminal.');
|
|
87
|
+
console.log('Profile(s) to modify:');
|
|
88
|
+
profiles.forEach(p => console.log(` - ${p}`));
|
|
89
|
+
console.log('');
|
|
90
|
+
|
|
91
|
+
const confirmed = await askConfirmation('Proceed with installation? (y/N): ');
|
|
92
|
+
if (!confirmed) {
|
|
93
|
+
console.log('Installation cancelled.');
|
|
94
|
+
process.exit(0);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let installed = 0;
|
|
98
|
+
let skipped = 0;
|
|
99
|
+
|
|
100
|
+
for (const profilePath of profiles) {
|
|
101
|
+
// Check if already configured
|
|
102
|
+
if (hasConfig(profilePath)) {
|
|
103
|
+
console.log(` [skip] ${profilePath} - already configured`);
|
|
104
|
+
skipped++;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Ensure directory exists
|
|
109
|
+
const dir = path.dirname(profilePath);
|
|
110
|
+
if (!fs.existsSync(dir)) {
|
|
111
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Append config block
|
|
115
|
+
try {
|
|
116
|
+
fs.appendFileSync(profilePath, configBlock, 'utf8');
|
|
117
|
+
console.log(` [done] ${profilePath}`);
|
|
118
|
+
installed++;
|
|
119
|
+
} catch (err) {
|
|
120
|
+
console.error(` [error] ${profilePath}: ${err.message}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
console.log('');
|
|
125
|
+
if (installed > 0) {
|
|
126
|
+
console.log(`Success! Auto-run configured in ${installed} profile(s).`);
|
|
127
|
+
console.log('Open a new terminal window to see the report on startup.');
|
|
128
|
+
} else if (skipped === profiles.length) {
|
|
129
|
+
console.log('Auto-run was already configured in all profiles.');
|
|
130
|
+
}
|
|
131
|
+
process.exit(0);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Uninstall auto-run from shell profiles
|
|
135
|
+
async function uninstallAutoRun() {
|
|
136
|
+
const profiles = getProfilePaths();
|
|
137
|
+
|
|
138
|
+
console.log('\nTR-200 Machine Report - Remove Auto-Run\n');
|
|
139
|
+
console.log('This will remove the auto-run configuration from your shell profile(s).');
|
|
140
|
+
console.log('Profile(s) to check:');
|
|
141
|
+
profiles.forEach(p => console.log(` - ${p}`));
|
|
142
|
+
console.log('');
|
|
143
|
+
|
|
144
|
+
const confirmed = await askConfirmation('Proceed with removal? (y/N): ');
|
|
145
|
+
if (!confirmed) {
|
|
146
|
+
console.log('Removal cancelled.');
|
|
147
|
+
process.exit(0);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
let removed = 0;
|
|
151
|
+
|
|
152
|
+
for (const profilePath of profiles) {
|
|
153
|
+
if (!fs.existsSync(profilePath)) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const content = fs.readFileSync(profilePath, 'utf8');
|
|
158
|
+
if (!content.includes(CONFIG_MARKER)) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Remove the config block (handles both Unix and PowerShell formats)
|
|
163
|
+
// Match from the comment line through the closing fi/}
|
|
164
|
+
const unixPattern = /\n?# TR-200 Machine Report \(npm\) - auto-run\nif command -v tr200 &> \/dev\/null; then\n tr200\nfi\n?/g;
|
|
165
|
+
const psPattern = /\n?# TR-200 Machine Report \(npm\) - auto-run\nif \(Get-Command tr200 -ErrorAction SilentlyContinue\) \{\n tr200\n\}\n?/g;
|
|
166
|
+
|
|
167
|
+
let newContent = content.replace(unixPattern, '');
|
|
168
|
+
newContent = newContent.replace(psPattern, '');
|
|
169
|
+
|
|
170
|
+
if (newContent !== content) {
|
|
171
|
+
try {
|
|
172
|
+
fs.writeFileSync(profilePath, newContent, 'utf8');
|
|
173
|
+
console.log(` [done] ${profilePath}`);
|
|
174
|
+
removed++;
|
|
175
|
+
} catch (err) {
|
|
176
|
+
console.error(` [error] ${profilePath}: ${err.message}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
console.log('');
|
|
182
|
+
if (removed > 0) {
|
|
183
|
+
console.log(`Success! Auto-run removed from ${removed} profile(s).`);
|
|
184
|
+
} else {
|
|
185
|
+
console.log('No auto-run configuration found in any profile.');
|
|
186
|
+
}
|
|
187
|
+
console.log('\nNote: To completely remove tr200, run: npm uninstall -g tr200');
|
|
188
|
+
process.exit(0);
|
|
189
|
+
}
|
|
18
190
|
|
|
19
191
|
// Locate the script files relative to this wrapper
|
|
20
192
|
const packageRoot = path.resolve(__dirname, '..');
|
|
@@ -36,6 +208,8 @@ function runReport() {
|
|
|
36
208
|
command = 'pwsh';
|
|
37
209
|
args = ['-ExecutionPolicy', 'Bypass', '-NoProfile', '-File', scriptPath];
|
|
38
210
|
|
|
211
|
+
let pwshFailed = false;
|
|
212
|
+
|
|
39
213
|
const child = spawn(command, args, {
|
|
40
214
|
stdio: 'inherit',
|
|
41
215
|
shell: false
|
|
@@ -44,6 +218,7 @@ function runReport() {
|
|
|
44
218
|
child.on('error', (err) => {
|
|
45
219
|
// If pwsh not found, try Windows PowerShell
|
|
46
220
|
if (err.code === 'ENOENT') {
|
|
221
|
+
pwshFailed = true;
|
|
47
222
|
const fallback = spawn('powershell', args, {
|
|
48
223
|
stdio: 'inherit',
|
|
49
224
|
shell: false
|
|
@@ -64,7 +239,10 @@ function runReport() {
|
|
|
64
239
|
});
|
|
65
240
|
|
|
66
241
|
child.on('close', (code) => {
|
|
67
|
-
|
|
242
|
+
// Only handle close if pwsh didn't fail (otherwise fallback handles it)
|
|
243
|
+
if (!pwshFailed) {
|
|
244
|
+
process.exit(code || 0);
|
|
245
|
+
}
|
|
68
246
|
});
|
|
69
247
|
|
|
70
248
|
} else {
|
|
@@ -102,7 +280,7 @@ function runReport() {
|
|
|
102
280
|
// Handle help flag
|
|
103
281
|
if (process.argv.includes('--help') || process.argv.includes('-h')) {
|
|
104
282
|
console.log(`
|
|
105
|
-
TR-200 Machine Report v2.0.
|
|
283
|
+
TR-200 Machine Report v2.0.1
|
|
106
284
|
|
|
107
285
|
Usage: tr200 [options]
|
|
108
286
|
report [options]
|
|
@@ -112,6 +290,8 @@ Displays system information in a formatted table with Unicode box-drawing.
|
|
|
112
290
|
Options:
|
|
113
291
|
-h, --help Show this help message
|
|
114
292
|
-v, --version Show version number
|
|
293
|
+
--install Set up auto-run on terminal/shell startup
|
|
294
|
+
--uninstall Remove auto-run from shell startup
|
|
115
295
|
|
|
116
296
|
More info: https://github.com/RealEmmettS/usgc-machine-report
|
|
117
297
|
`);
|
|
@@ -120,9 +300,17 @@ More info: https://github.com/RealEmmettS/usgc-machine-report
|
|
|
120
300
|
|
|
121
301
|
// Handle version flag
|
|
122
302
|
if (process.argv.includes('--version') || process.argv.includes('-v')) {
|
|
123
|
-
console.log('2.0.
|
|
303
|
+
console.log('2.0.1');
|
|
124
304
|
process.exit(0);
|
|
125
305
|
}
|
|
126
306
|
|
|
127
|
-
//
|
|
128
|
-
|
|
307
|
+
// Handle install flag
|
|
308
|
+
if (process.argv.includes('--install')) {
|
|
309
|
+
installAutoRun();
|
|
310
|
+
} else if (process.argv.includes('--uninstall')) {
|
|
311
|
+
// Handle uninstall flag
|
|
312
|
+
uninstallAutoRun();
|
|
313
|
+
} else {
|
|
314
|
+
// Run the report
|
|
315
|
+
runReport();
|
|
316
|
+
}
|
package/machine_report.sh
CHANGED
|
@@ -7,6 +7,49 @@
|
|
|
7
7
|
# Supports: Linux (all major distros), macOS 10.13+, partial BSD support
|
|
8
8
|
# Requires: Bash 4.0+ (macOS users: brew install bash)
|
|
9
9
|
|
|
10
|
+
TR200_VERSION="2.0.1"
|
|
11
|
+
|
|
12
|
+
# Handle command-line arguments
|
|
13
|
+
show_help() {
|
|
14
|
+
cat << 'EOF'
|
|
15
|
+
|
|
16
|
+
TR-200 Machine Report v2.0.1
|
|
17
|
+
|
|
18
|
+
Usage: machine_report.sh [options]
|
|
19
|
+
report [options]
|
|
20
|
+
|
|
21
|
+
Displays system information in a formatted table with Unicode box-drawing.
|
|
22
|
+
|
|
23
|
+
Options:
|
|
24
|
+
--help, -h Show this help message
|
|
25
|
+
--version, -v Show version number
|
|
26
|
+
|
|
27
|
+
When installed via npm (tr200):
|
|
28
|
+
tr200 Run the machine report
|
|
29
|
+
tr200 --help Show help (includes install/uninstall options)
|
|
30
|
+
tr200 --install Set up auto-run on terminal startup
|
|
31
|
+
tr200 --uninstall Remove auto-run from shell startup
|
|
32
|
+
|
|
33
|
+
When installed via install.sh:
|
|
34
|
+
report Run the machine report
|
|
35
|
+
~/.machine_report.sh Run directly
|
|
36
|
+
|
|
37
|
+
More info: https://github.com/RealEmmettS/usgc-machine-report
|
|
38
|
+
|
|
39
|
+
EOF
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
case "${1:-}" in
|
|
43
|
+
--help|-h)
|
|
44
|
+
show_help
|
|
45
|
+
exit 0
|
|
46
|
+
;;
|
|
47
|
+
--version|-v)
|
|
48
|
+
echo "$TR200_VERSION"
|
|
49
|
+
exit 0
|
|
50
|
+
;;
|
|
51
|
+
esac
|
|
52
|
+
|
|
10
53
|
# Global variables
|
|
11
54
|
MIN_NAME_LEN=5
|
|
12
55
|
MAX_NAME_LEN=13
|