-
Notifications
You must be signed in to change notification settings - Fork 592
Add instructions to setup the file for Clink #1403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Added extended instructions for clink.
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Removed unnecessary match and fixed indent.
|
Guess should have check PRs first... this is what I came up with:
if os.getenv("FNM_AUTORUN_GUARD") == nil then
os.setenv("FNM_AUTORUN_GUARD", "1")
local function parse_fnm_env()
local handle = io.popen('fnm env --use-on-cd 2>nul')
if not handle then return nil end
local out = handle:read("*a")
handle:close()
local env = {}
for line in out:gmatch("[^\r\n]+") do
-- Matches: set VAR=VALUE (quotes rarely used, but handle if present)
local var, value = line:match("^[Ss][Ee][Tt]%s+([^=]+)=(.*)$")
if var and value then
value = value:gsub('^"(.*)"$', '%1') -- remove surrounding quotes if present
env[var:match("^%s*(.-)%s*$")] = value -- trim spaces from var
end
-- local line = line:match("^([Dd][Oo][Ss][Kk][Ee][Yy]%s+.*)$")
-- if line then
-- os.execute(line)
-- end
end
return env, out
end
local function setup_fnm()
local env, raw = parse_fnm_env()
if not env or not raw then return end
for var, value in pairs(env) do
os.setenv(var, value)
end
end
setup_fnm()
end
local function check_and_use_fnm()
-- Check FNM_VERSION_FILE_STRATEGY environment variable
local fnm_strategy = os.getenv("FNM_VERSION_FILE_STRATEGY")
-- Check if we should use recursive strategy
if fnm_strategy == "recursive" then
os.execute("fnm use --silent-if-unchanged")
else
-- Check for .nvmrc file
local nvmrc = io.open(".nvmrc", "r")
if nvmrc ~= nil then
io.close(nvmrc)
os.execute("fnm use --silent-if-unchanged")
else
-- Check for .node-version file
local node_version = io.open(".node-version", "r")
if node_version ~= nil then
io.close(node_version)
os.execute("fnm use --silent-if-unchanged")
end
end
end
end
-- remove fnm symlinks on exit
clink.onendedit(function(line)
if line:match("^exit") then
local path = os.getenv("FNM_MULTISHELL_PATH")
if path then
os.rmdir(path)
end
end
end)
-- doskey replacement
clink.onbeginedit(check_and_use_fnm) |
|
I've updated the script: this gist includes working doskey replacement and functions correctly even when launching the terminal using “Open Prompt Here” from Windows Explorer. |
Thanks! That's really a better solution. So what about open a pr for this project? If I merged these into my code manually, there would be no trace of you in the commit log (thanks via comments would probably not be appropriate here). |
- doskey replacement with lua implementation - remove symlink on exit
improved clink lua script:
|
excuse me but what is clink |
Here is it's GitHub repo: chrisant996/clink |
Added instructions for using fnm with Clink.