Open yanecc opened 6 months ago
If you are interested, you can provide a PR. ;)
btw it seems duplicated with #46
I'm interested in implementing this. What could I do? I've checked other shells' implementation and there's a little magic inside what the implementors should know.
My questions:
pre_prompt
, pre_execution
hook. I made PoC with pre_prompt only[1] and it seems to work correctly (not much-tested yet). Fish seems to utilize preexec
hook but why? I don't know much about fish so cannot understand why is it required. Should I implement this for nushell?__VFOX_SHELL
, __VFOX_PID
, and __VFOX_PREVIOUS_PATHS
. When are they updated?[1]: it's not complete yet. just sharing purpose.
# config.nu
export-env {
$env.__VFOX_SHELL = 'pwsh'; # use dummy shell for not-editing vfox code yet
$env.__VFOX_PID = $nu.pid;
vfox env --cleanup | null
# like mise, we should support edge cases
# seealso(mise's impl): https://github.com/jdx/mise/blob/e6448b335cf99db6fb2bdfd4c3f49ba255c2d8de/src/shell/nushell.rs#L38-L42)
$env.config = (
$env.config |
update hooks.pre_prompt { |old_hooks| old_hooks ++ {
# I parsed pwsh output for a temporal workaround, it could be better.
for entry in (
vfox env -s pwsh | split row "';" | str replace "='" "=" | parse '{name}={value}'
) {
match $entry.name {
'$env:PATH' => {
load-env { Path: ($entry.value | split row ';') };
}
'$env:__VFOX_PREVIOUS_PATHS' => {
load-env { __VFOX_PREVIOUS_PATHS: $entry.value };
}
}
}
}}
)
}
@RanolP I've got this for Nushell: `function PLUGIN:Available(ctx) local versions = {} local resp, err = http.get({ url = util.RELEASES_URL })
if err ~= nil or resp.status_code ~= 200 then
error("Getting releases failed: " .. err)
end
local type = util:getOsTypeAndArch()
local releases = json.decode(resp.body)
for _, release in ipairs(releases) do
local version = release.tag_name
local url = ""
for _, asset in ipairs(release.assets) do
if asset.name:find(type.osType) and asset.name:find(type.archType) then
url = asset.browser_download_url
break
end
end
if url ~= "" then
table.insert(versions, {
version = version,
url = url
})
end
end
return versions
end`
and util.getOsTypeAndArch: util.RELEASES_URL = "https://api.github.com/repos/nushell/nushell/releases"
function util:getOsTypeAndArch() local osType = RUNTIME.osType local archType = RUNTIME.archType if RUNTIME.osType == "darwin" then osType = "macoS" elseif RUNTIME.osType == "linux" then osType = "linux" elseif RUNTIME.osType == "windows" then osType = "windows" end if RUNTIME.archType == "amd64" then archType = "x86_64" elseif RUNTIME.archType == "arm64" then archType = "-armv" -- TODO: Find out exact version for 386 elseif RUNTIME.archType == "386" then archType = "x86" end return { osType = osType, archType = archType } end
I'm interested in implementing this. What could I do? I've checked other shells' implementation and there's a little magic inside what the implementors should know.
My questions:
What should I hook for?
- afaik, nushell doesn't provide an exit hook. Is it ok? (I think it's ok because Clink implementation seems to have missed this)
We can execute cleanup task when shell
activate vfox
first time. Like pwsh
:
- nushell provides
pre_prompt
,pre_execution
hook. I made PoC with pre_prompt only[1] and it seems to work correctly (not much-tested yet). Fish seems to utilizepreexec
hook but why? I don't know much about fish so cannot understand why is it required. Should I implement this for nushell?
pre_prompt
enough.
What env vars should I update?
- I found
__VFOX_SHELL
,__VFOX_PID
, and__VFOX_PREVIOUS_PATHS
. When are they updated?
__VFOX_PID
and __VFOX_SHELL
will be set when activate vfox
first time, but __VFOX_PID
needs to be set in a nushell script.
In 0.5.0, __VFOX_PREVIOUS_PATHS
is no longer required.
[1]: it's not complete yet. just sharing purpose.
# config.nu export-env { $env.__VFOX_SHELL = 'pwsh'; # use dummy shell for not-editing vfox code yet $env.__VFOX_PID = $nu.pid; vfox env --cleanup | null # like mise, we should support edge cases # seealso(mise's impl): https://github.com/jdx/mise/blob/e6448b335cf99db6fb2bdfd4c3f49ba255c2d8de/src/shell/nushell.rs#L38-L42) $env.config = ( $env.config | update hooks.pre_prompt { |old_hooks| old_hooks ++ { # I parsed pwsh output for a temporal workaround, it could be better. for entry in ( vfox env -s pwsh | split row "';" | str replace "='" "=" | parse '{name}={value}' ) { match $entry.name { '$env:PATH' => { load-env { Path: ($entry.value | split row ';') }; } '$env:__VFOX_PREVIOUS_PATHS' => { load-env { __VFOX_PREVIOUS_PATHS: $entry.value }; } } } }} ) }
@RanolP Just wondering if you've made any headway on this? Would be helpful to me if you have a working version but no worries if not
Recently I had no times to implement this sry
btw it seems duplicated with #46
I'm interested in implementing this. What could I do? I've checked other shells' implementation and there's a little magic inside what the implementors should know.
My questions:
What should I hook for?
- afaik, nushell doesn't provide an exit hook. Is it ok? (I think it's ok because Clink implementation seems to have missed this)
- nushell provides
pre_prompt
,pre_execution
hook. I made PoC with pre_prompt only[1] and it seems to work correctly (not much-tested yet). Fish seems to utilizepreexec
hook but why? I don't know much about fish so cannot understand why is it required. Should I implement this for nushell?What env vars should I update?
- I found
__VFOX_SHELL
,__VFOX_PID
, and__VFOX_PREVIOUS_PATHS
. When are they updated?[1]: it's not complete yet. just sharing purpose.
# config.nu export-env { $env.__VFOX_SHELL = 'pwsh'; # use dummy shell for not-editing vfox code yet $env.__VFOX_PID = $nu.pid; vfox env --cleanup | null # like mise, we should support edge cases # seealso(mise's impl): https://github.com/jdx/mise/blob/e6448b335cf99db6fb2bdfd4c3f49ba255c2d8de/src/shell/nushell.rs#L38-L42) $env.config = ( $env.config | update hooks.pre_prompt { |old_hooks| old_hooks ++ { # I parsed pwsh output for a temporal workaround, it could be better. for entry in ( vfox env -s pwsh | split row "';" | str replace "='" "=" | parse '{name}={value}' ) { match $entry.name { '$env:PATH' => { load-env { Path: ($entry.value | split row ';') }; } '$env:__VFOX_PREVIOUS_PATHS' => { load-env { __VFOX_PREVIOUS_PATHS: $entry.value }; } } } }} ) }
This worked for me. the only change I had to do was put it directly in the pre_prompt hook in config.nu instead of appending it.
Well, nushell is also a common choice on Windows. Thanks a lot.