Yelp / aactivator

Automatically source and unsource a project's environment
MIT License
145 stars 17 forks source link

Add fish shell support #24

Open ipwnponies opened 6 years ago

ipwnponies commented 6 years ago

It would be nice to add support for fish shell users. This would require targeting a different virtualenv activation script (activate.fish) and using fish syntax for the output eval command.

If fully supporting fish is too much scope, then maybe we can expose additional sub-commands (like security-check) that will enable fish users to implement remainder of the logic.

If you're receptive to this idea, I can investigate further once we decide on general direction.

pratikmallya commented 2 years ago

Are there any workarounds? Trying to see if there's some hacky way of using aactivator from fish until/if this feature is implemented.

asottile commented 2 years ago

to implement this:

ipwnponies commented 2 years ago

@asottile You're right about posix shell compatibility, where I hit a wall in trying to add fish support. aactivator uses a template string and some syntax will not work for fish. But rather than swap to a different template string, I feel there are enough fish-isms that can better work here for maintainability and compatibility (alluded to with "expose sub-commands like security-check). Rather than constrain to the interface of "something that can be source".

https://github.com/Yelp/aactivator/blob/e0a598fee270417ac31db640320351eb33f75860/aactivator.py#L49-L60

Reference

precmd and postcmd

Pre and post command is handled by registering onto events. Docs:

fish_preexec, which is emitted right before executing an interactive command. The commandline is passed as the first parameter. Not emitted if command is empty.

fish_postexec, which is emitted right after executing an interactive command. The commandline is passed as the first parameter. Not emitted if command is empty.

function aactivate --on-event fish_preexec
  source venv/bin/activate.fish
end

source

You can call source on a file or you can pipe stdin to source.

aactivator.py --fish | source