pkgx
pkgx copied to clipboard
Shell Integration Not Working on Fish Shell
Hi
We are trying to integrate the shell to run the dev command. But unfortunately the shell integration is not working on fish shell. Is there any way to integrate it on fish shell??
This is being built #838, help welcome as I am not familiar with fish.
Whats missing in #838 for the task to be complete?
Been a week so i don't recall precisely (sadly I am super busy with CEO duties RN)
If you checkout the code and try to SHELL=fish eval deno task run --shellcode we then need the shellcode functions to work
$ x # most complex, partially working
$ env +foo # should be easy
$ dev # again should be pretty easy
I should be able to resume work on this next week, but feel free to get it working.
IMO if x works that's enough for now, we can then make dev work after. But as said dev is probs easiest.
All the code is in shellcode.ts
A partial workaround for fish is to use direnv. Install it, and drop a file .envrc with the following content in your project folder:
source <(pkgx --internal.activate $(realpath .))
This will act very similarly to the dev command -- it will resolve the environment and activate it using pkgx, and deactivate it once you navigate outside of the folder. This should even have greater IDE support since direnv has been around for a while and has battle-tested extensions for most IDEs.
Here's a "poor man's" implementation for the shell integration in Fish:
function x; bass source (pkgx +(string split -f1 ' ' $history[1]) | psub) && eval $history[1]; end;
function envx; bass source (pkgx "$argv" | psub); end;
function dev; bass source (pkgx --internal.activate $(realpath .) | psub); end;
It depends on https://github.com/edc/bass for sourcing bash scripts, and the dev command does not auto-deactivate (it's probably doable with function ... --on-variable PWD -- https://fishshell.com/docs/current/cmds/function.html -- but that would be harder to serve through bass given that it does not port over bash functions -- as said above, I recommend using direnv for this use case). env is called envx not to bother with Unix env compatibility.
@JanPokorny Thanks for the workaround with direnv. Unfortunately this requires a .envrc file in every project folder.
Looking forward to a native Fish solution as I would like to give this shell a try. Unfortunately I have no experience with Fish and its scripting so I can't help here.
@svenjacobs You could just run echo 'source <(pkgx --internal.activate $(realpath .))' >>.envrc && echo '.envrc' >>.git/info/exclude in every project folder and be done with it. You could alias it to dev-setup or something and just use that instead of dev.
Sure, but I don't want to add a file to every project that my colleagues don't need 😉 Of course I could add the file to the global .gitignore but as I said a native solution would be much appreciated 😃
@svenjacobs The snippet I posted above adds the file to a local ignore file .git/info/exclude