pythonaliasespipenv

Is there any way to add custom aliases into pipenv shell?


Is there any way to configure pipenv in a way that it will load custom bash aliases in its shell?

I tried to just put my alias into the .env file, but that didn't work. After that I googled it, but couldn't find a solution.


Solution

  • pipenv shell appears to take additional arguments that are sent as an initial command to the shell that it starts. A simulated session follows:

    $ cat tmp.sh
    echo hi
    $ pipenv shell . tmp.sh
    Spawning environment shell (/bin/bash). Use 'exit' to leave.
    . .../bin/activate
    . . tmp.sh
    $ . .../bin/activate
    $ . tmp.sh
    hi
    $
    

    Since pipenv shell just starts an interactive session of the shell named by the SHELL environment variable, you can add code to your usual .bashrc file to source a special local file on start-up, if it exists:

    if [[ -f .pipenvshrc ]]; then
      . .pipenvshrc
    fi
    

    You can also play around with the idea of using the value of $VIRTUAL_ENV that pipenv shell adds to the environment to choose a file to source.