pkgx icon indicating copy to clipboard operation
pkgx copied to clipboard

Shell Integration Not Working on Fish Shell

Open jubinmytheen opened this issue 2 years ago • 9 comments
trafficstars

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??

jubinmytheen avatar Nov 01 '23 05:11 jubinmytheen

This is being built #838, help welcome as I am not familiar with fish.

mxcl avatar Nov 02 '23 19:11 mxcl

Whats missing in #838 for the task to be complete?

philipgiuliani avatar Nov 09 '23 11:11 philipgiuliani

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

mxcl avatar Nov 09 '23 12:11 mxcl

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.

JanPokorny avatar Mar 21 '24 14:03 JanPokorny

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 avatar May 13 '24 10:05 JanPokorny

@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 avatar May 13 '24 11:05 svenjacobs

@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.

JanPokorny avatar May 13 '24 13:05 JanPokorny

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 avatar May 14 '24 06:05 svenjacobs

@svenjacobs The snippet I posted above adds the file to a local ignore file .git/info/exclude

JanPokorny avatar May 14 '24 07:05 JanPokorny