@shreyash1601/oopsify 1.0.2 → 1.0.3
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/bin/index.js +31 -58
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -19,16 +19,15 @@ const os = require('os');
|
|
|
19
19
|
|
|
20
20
|
if (command === 'setup') {
|
|
21
21
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
|
|
31
|
-
);
|
|
22
|
+
const { execSync } = require('child_process');
|
|
23
|
+
|
|
24
|
+
if (isWindows) {
|
|
25
|
+
try {
|
|
26
|
+
// 👉 Get actual PowerShell profile path
|
|
27
|
+
const profilePath = execSync(
|
|
28
|
+
'powershell -NoProfile -Command "$PROFILE"',
|
|
29
|
+
{ encoding: 'utf-8' }
|
|
30
|
+
).trim();
|
|
32
31
|
|
|
33
32
|
const config = String.raw`
|
|
34
33
|
# >>> oopsify setup >>>
|
|
@@ -42,27 +41,25 @@ function global:prompt {
|
|
|
42
41
|
|
|
43
42
|
$shouldTrigger = $false
|
|
44
43
|
|
|
45
|
-
if (-not
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
$shouldTrigger = $true
|
|
55
|
-
}
|
|
44
|
+
if (-not $?) {
|
|
45
|
+
$shouldTrigger = $true
|
|
46
|
+
}
|
|
47
|
+
elseif ($LASTEXITCODE -ne 0) {
|
|
48
|
+
$shouldTrigger = $true
|
|
49
|
+
}
|
|
50
|
+
elseif ($Error.Count -gt 0) {
|
|
51
|
+
$shouldTrigger = $true
|
|
52
|
+
}
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
if ($shouldTrigger) {
|
|
55
|
+
if ($currentTime - $global:lastOopsifyTime -gt 2) {
|
|
56
|
+
oopsify
|
|
57
|
+
$global:lastOopsifyTime = $currentTime
|
|
58
|
+
}
|
|
61
59
|
}
|
|
62
|
-
}
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
}
|
|
61
|
+
$Error.Clear()
|
|
62
|
+
}
|
|
66
63
|
|
|
67
64
|
$global:isFirstRun = $false
|
|
68
65
|
$global:LASTEXITCODE = 0
|
|
@@ -72,6 +69,7 @@ function global:prompt {
|
|
|
72
69
|
# <<< oopsify setup <<<
|
|
73
70
|
`;
|
|
74
71
|
|
|
72
|
+
// 👉 Ensure directory exists
|
|
75
73
|
fs.mkdirSync(path.dirname(profilePath), { recursive: true });
|
|
76
74
|
|
|
77
75
|
let existing = '';
|
|
@@ -81,42 +79,17 @@ function global:prompt {
|
|
|
81
79
|
|
|
82
80
|
if (!existing.includes('oopsify setup')) {
|
|
83
81
|
fs.appendFileSync(profilePath, config);
|
|
84
|
-
|
|
82
|
+
|
|
83
|
+
console.log('✅ Oopsify auto-configured successfully!');
|
|
85
84
|
console.log('👉 Restart your terminal.');
|
|
86
85
|
} else {
|
|
87
86
|
console.log('⚠️ Oopsify already configured.');
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const config = `
|
|
94
|
-
# >>> oopsify setup >>>
|
|
95
|
-
oopsify_run() {
|
|
96
|
-
"$@"
|
|
97
|
-
if [ $? -ne 0 ]; then
|
|
98
|
-
oopsify
|
|
99
|
-
fi
|
|
100
|
-
}
|
|
101
|
-
alias run="oopsify_run"
|
|
102
|
-
# <<< oopsify setup <<<
|
|
103
|
-
`;
|
|
104
|
-
|
|
105
|
-
let existing = '';
|
|
106
|
-
if (fs.existsSync(bashrc)) {
|
|
107
|
-
existing = fs.readFileSync(bashrc, 'utf-8');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (!existing.includes('oopsify setup')) {
|
|
111
|
-
fs.appendFileSync(bashrc, config);
|
|
112
|
-
console.log('✅ Oopsify configured for bash!');
|
|
113
|
-
console.log('👉 Run: source ~/.bashrc');
|
|
114
|
-
} else {
|
|
115
|
-
console.log('⚠️ Already configured.');
|
|
116
|
-
}
|
|
89
|
+
} catch (err) {
|
|
90
|
+
console.error('❌ Failed to configure PowerShell profile');
|
|
117
91
|
}
|
|
118
|
-
|
|
119
|
-
return;
|
|
92
|
+
}
|
|
120
93
|
}
|
|
121
94
|
// 👉 LIST COMMAND
|
|
122
95
|
if (command === 'list') {
|