fnva 0.0.41 → 0.0.43
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/README.md +3 -1
- package/package.json +1 -1
- package/platforms/darwin-arm64/fnva +0 -0
- package/platforms/darwin-x64/fnva +0 -0
- package/platforms/linux-arm64/fnva +0 -0
- package/platforms/linux-x64/fnva +0 -0
- package/platforms/win32-x64/fnva.exe +0 -0
- package/scripts/install-shell-integration.js +55 -23
package/README.md
CHANGED
|
@@ -14,16 +14,18 @@ Cross-platform environment switcher for Java, Claude Code (CC), and LLM setups.
|
|
|
14
14
|
|
|
15
15
|
## Quick start
|
|
16
16
|
|
|
17
|
-
- Init shell (Bash/Zsh): `eval "$(fnva env env --shell bash)"`
|
|
17
|
+
- Init shell (Bash/Zsh): `eval "$(fnva env env --shell bash)"`
|
|
18
18
|
PowerShell: `fnva env env --shell powershell | Out-String | Invoke-Expression`
|
|
19
19
|
- Scan Java: `fnva java scan`
|
|
20
20
|
- Switch Java for current session: `eval "$(fnva java use jdk-17)"`
|
|
21
21
|
- Switch CC profile: `eval "$(fnva cc use glmcc)"`
|
|
22
|
+
- New terminals auto-restore your last active environment
|
|
22
23
|
|
|
23
24
|
## What it does
|
|
24
25
|
|
|
25
26
|
- Manages multiple Java, CC, and generic LLM configurations.
|
|
26
27
|
- Generates shell snippets to activate environments per session or by default.
|
|
28
|
+
- **Auto-restore** — new terminals automatically restore the last active CC/Java environment.
|
|
27
29
|
- Stores config at `~/.fnva/config.toml` (Windows: `%USERPROFILE%\.fnva\config.toml`).
|
|
28
30
|
- Ships as a single binary; no background daemon.
|
|
29
31
|
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/platforms/linux-x64/fnva
CHANGED
|
Binary file
|
|
Binary file
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// Shell integration installer for fnva (npm postinstall helper).
|
|
4
|
-
//
|
|
4
|
+
// Uses fnva's built-in template system for shell integration scripts.
|
|
5
5
|
|
|
6
6
|
const fs = require('fs');
|
|
7
7
|
const path = require('path');
|
|
8
8
|
const os = require('os');
|
|
9
|
+
const { spawnSync } = require('child_process');
|
|
9
10
|
|
|
10
11
|
// Absolute path to the packaged fnva shim (bin/fnva.js)
|
|
11
12
|
const FNVA_SHIM = path.resolve(__dirname, '..', 'bin', 'fnva.js');
|
|
@@ -37,49 +38,70 @@ function getShellConfigPath(shell) {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
// Get integration script from fnva command (uses Rust templates)
|
|
42
|
+
function getIntegrationScript(shell) {
|
|
43
|
+
try {
|
|
44
|
+
const result = spawnSync('node', [FNVA_SHIM, 'env', 'shell-integration', '-s', shell], {
|
|
45
|
+
encoding: 'utf8',
|
|
46
|
+
cwd: path.resolve(__dirname, '..')
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (result.status === 0 && result.stdout) {
|
|
50
|
+
return result.stdout;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.log(`Warning: Failed to get integration script from fnva (exit code: ${result.status})`);
|
|
54
|
+
if (result.stderr) {
|
|
55
|
+
console.log(`stderr: ${result.stderr}`);
|
|
56
|
+
}
|
|
57
|
+
return '';
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.log(`Warning: Failed to call fnva for integration script: ${error.message}`);
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
40
64
|
function getPowerShellFunction() {
|
|
65
|
+
// Get integration script from Rust template
|
|
66
|
+
const integrationScript = getIntegrationScript('powershell');
|
|
67
|
+
|
|
41
68
|
return `
|
|
69
|
+
${integrationScript}
|
|
70
|
+
|
|
42
71
|
# fnva auto integration (added by npm install)
|
|
43
72
|
function fnva {
|
|
44
73
|
if ($args.Count -ge 2 -and ($args[0] -eq "java" -or $args[0] -eq "llm" -or $args[0] -eq "cc") -and ($args[1] -eq "use")) {
|
|
45
74
|
$tempFile = Join-Path $env:TEMP ("fnva_script_" + (Get-Random) + ".ps1")
|
|
46
75
|
|
|
47
76
|
try {
|
|
48
|
-
|
|
77
|
+
# Directly pipe output to temp file to avoid encoding issues
|
|
78
|
+
& fnva.cmd @args 2>&1 | Out-File -FilePath $tempFile -Encoding UTF8
|
|
49
79
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
80
|
+
# Check if file contains environment variables
|
|
81
|
+
$content = Get-Content $tempFile -Raw -Encoding UTF8
|
|
82
|
+
if ($content -match '\\$env:' -or $content -match 'Write-Host') {
|
|
83
|
+
# Use dot sourcing to execute in current scope
|
|
84
|
+
. $tempFile
|
|
53
85
|
} else {
|
|
54
|
-
$
|
|
86
|
+
$content
|
|
55
87
|
}
|
|
56
88
|
} finally {
|
|
57
89
|
if (Test-Path $tempFile) { Remove-Item $tempFile -ErrorAction SilentlyContinue }
|
|
58
90
|
}
|
|
59
91
|
} else {
|
|
60
|
-
|
|
92
|
+
& fnva.cmd @args
|
|
61
93
|
}
|
|
62
94
|
}
|
|
63
95
|
`;
|
|
64
96
|
}
|
|
65
97
|
|
|
66
|
-
function resolveBinaryPath() {
|
|
67
|
-
// Prefer real binary, avoid this function name
|
|
68
|
-
if (process.platform === 'win32') {
|
|
69
|
-
return process.argv[0];
|
|
70
|
-
}
|
|
71
|
-
let bin = '';
|
|
72
|
-
try {
|
|
73
|
-
const which = require('child_process').spawnSync('which', ['fnva'], { encoding: 'utf8' });
|
|
74
|
-
if (which.status === 0) {
|
|
75
|
-
bin = (which.stdout || '').trim();
|
|
76
|
-
}
|
|
77
|
-
} catch {}
|
|
78
|
-
return bin;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
98
|
function getBashFunction() {
|
|
99
|
+
// Get integration script from Rust template
|
|
100
|
+
const integrationScript = getIntegrationScript('bash');
|
|
101
|
+
|
|
82
102
|
return `
|
|
103
|
+
${integrationScript}
|
|
104
|
+
|
|
83
105
|
# fnva auto integration (added by npm install)
|
|
84
106
|
fnva() {
|
|
85
107
|
local __fnva_bin="${FNVA_SHIM}"
|
|
@@ -104,7 +126,12 @@ fnva() {
|
|
|
104
126
|
}
|
|
105
127
|
|
|
106
128
|
function getFishFunction() {
|
|
129
|
+
// Get integration script from Rust template
|
|
130
|
+
const integrationScript = getIntegrationScript('fish');
|
|
131
|
+
|
|
107
132
|
return `
|
|
133
|
+
${integrationScript}
|
|
134
|
+
|
|
108
135
|
# fnva auto integration (added by npm install)
|
|
109
136
|
function fnva
|
|
110
137
|
set __fnva_bin "${FNVA_SHIM}"
|
|
@@ -132,7 +159,7 @@ function getShellFunction(shell) {
|
|
|
132
159
|
return getPowerShellFunction();
|
|
133
160
|
case 'bash':
|
|
134
161
|
case 'zsh':
|
|
135
|
-
return getBashFunction();
|
|
162
|
+
return getBashFunction(); // zsh 使用和 bash 相同的语法
|
|
136
163
|
case 'fish':
|
|
137
164
|
return getFishFunction();
|
|
138
165
|
default:
|
|
@@ -171,6 +198,11 @@ function installShellIntegration() {
|
|
|
171
198
|
|
|
172
199
|
const functionCode = getShellFunction(shell);
|
|
173
200
|
|
|
201
|
+
if (!functionCode) {
|
|
202
|
+
console.log('Failed to generate shell integration script');
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
|
|
174
206
|
if (fs.existsSync(configPath)) {
|
|
175
207
|
const content = fs.readFileSync(configPath, 'utf8');
|
|
176
208
|
fs.writeFileSync(configPath, content + '\n' + functionCode);
|