Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save smetroid/e91f2ba50a6bf338f80bcfb74cb6cd06 to your computer and use it in GitHub Desktop.
Save smetroid/e91f2ba50a6bf338f80bcfb74cb6cd06 to your computer and use it in GitHub Desktop.

Revisions

  1. @kishannareshpal kishannareshpal revised this gist Mar 23, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion activatevenv.plugin.sh
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    # To deactivate run `deactivate` and to manually activate run `activatevenv`
    function activatevenv() {
    # Names of possible virtualenv directories
    VIRTUALENV_DIRS=(("venv/" "env/" ".env/" ".venv/" "${PWD##*/}")
    VIRTUALENV_DIRS=("venv/" "env/" ".env/" ".venv/" "${PWD##*/}")

    for dir in $VIRTUALENV_DIRS; do
    if [[ -d "${dir}" ]]; then
  2. @kishannareshpal kishannareshpal renamed this gist Mar 23, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @kishannareshpal kishannareshpal revised this gist Mar 21, 2022. 2 changed files with 4 additions and 4 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -21,6 +21,6 @@ Download the `activatevenv.plugin.sh` into your computer.


    ## Usage
    For existing projects, simply `cd` into that directory and it should contain either a `venv/`, `.venv/`, and the script will activate it automatically!! (Just as you would do with source ./venv/bin/activate).
    Simply `cd` into a project directory with a python virtual environment setup (with any of these names: `venv/`, `.venv/`, `env` or `.env`), and the script will activate it automatically for you (just as you would do with `source ./venv/bin/activate`).

    If you are creating a new virtualenv, run `python -m <venv|virtualenv> <venv|.venv>` in your root directory and to activate it manually use call `activatevenv` (or if you cd back into your project it will automatically activate it without the need of calling activatevenv).
    If you are creating a new virtualenv, run `python -m <venv|virtualenv> <venv|.venv|.env|env>` in your root directory and to activate it manually call `activatevenv` (also when you cd back into your project folder it will automatically activate it).
    4 changes: 2 additions & 2 deletions activatevenv.plugin.sh
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    # .
    # ├── <other_project_files>
    # ├── ...
    # └── <.venv|venv>
    # └── <.venv|venv|.env|env>
    # ├── bin
    # ├── include
    # └── lib
    @@ -13,7 +13,7 @@
    # To deactivate run `deactivate` and to manually activate run `activatevenv`
    function activatevenv() {
    # Names of possible virtualenv directories
    VIRTUALENV_DIRS=("venv/" ".venv/" "${PWD##*/}")
    VIRTUALENV_DIRS=(("venv/" "env/" ".env/" ".venv/" "${PWD##*/}")
    for dir in $VIRTUALENV_DIRS; do
    if [[ -d "${dir}" ]]; then
  4. @kishannareshpal kishannareshpal revised this gist Dec 27, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion activatevenv.plugin.sh
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ function activatevenv() {
    }
    activatevenv

    # Extension for `cd` command in order to automatically acticate virtualenv
    # Extension for `cd` command in order to automatically activate virtualenv when changin directories.
    function cd() {
    builtin cd $1
    # Try activating venv
  5. @kishannareshpal kishannareshpal revised this gist Dec 27, 2020. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -17,9 +17,10 @@ Download the `activatevenv.plugin.sh` into your computer.
    ```

    ### Manually
    1. Simply copy and paste the script to the bottom of your `~/.bashrc` or `~/.zshrc` and restart your terminal.
    1. Copy and paste the `activatevend.plugin.sh` script to the bottom of your `~/.bashrc` or `~/.zshrc` and restart your terminal.


    ## Usage
    For existing projects, simply `cd` into your any directory that contains either a `venv/`, `.venv/` virtualenv created and the script will activate it automatically (Just as you would do with source ./venv/bin/activate)
    If you are creating a new virtualenv run `python -m <venv|virtualenv> <venv|.venv>` in your root directory and to activate it manually use call `activatevenv` (or if you cd back into your project it will automatically activate it without the need of calling activatevenv).
    For existing projects, simply `cd` into that directory and it should contain either a `venv/`, `.venv/`, and the script will activate it automatically!! (Just as you would do with source ./venv/bin/activate).

    If you are creating a new virtualenv, run `python -m <venv|virtualenv> <venv|.venv>` in your root directory and to activate it manually use call `activatevenv` (or if you cd back into your project it will automatically activate it without the need of calling activatevenv).
  6. @kishannareshpal kishannareshpal revised this gist Dec 18, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions activatevenv.plugin.sh
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,7 @@ function activatevenv() {
    if [[ -e "./${dir}/bin/activate" ]]; then
    source ./$dir/bin/activate
    echo "Virtual environment activated automatically"
    break
    fi
    fi
    done
  7. @kishannareshpal kishannareshpal revised this gist Dec 18, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #### This is a custom shell script I wrote in order to ease my workflow when dealing with Python Virtual Environments.

    ## Installation
    Download the `activateenv.plugin.sh` into your computer.
    Download the `activatevenv.plugin.sh` into your computer.
    ### oh-my-zsh
    1. Download the script into `$ZSH_CUSTOM/plugins/<plugin_name>/activatevenv/`. See [oh-my-zsh Plugin Customization Wiki](https://github.com/ohmyzsh/ohmyzsh/wiki/Customization)
    ```sh
  8. @kishannareshpal kishannareshpal revised this gist Dec 18, 2020. 2 changed files with 25 additions and 2 deletions.
    25 changes: 25 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #### This is a custom shell script I wrote in order to ease my workflow when dealing with Python Virtual Environments.

    ## Installation
    Download the `activateenv.plugin.sh` into your computer.
    ### oh-my-zsh
    1. Download the script into `$ZSH_CUSTOM/plugins/<plugin_name>/activatevenv/`. See [oh-my-zsh Plugin Customization Wiki](https://github.com/ohmyzsh/ohmyzsh/wiki/Customization)
    ```sh
    # Use curl or download manually from https://git.io/JLBHr
    (mkdir activatevenv; cd activatevenv) && curl -L --url https://git.io/JLBHr --output ./activatevenv/activatevenv.plugin.zsh
    ````
    2. Edit your `~/.zshrc`:
    ```sh
    # Add activatevenv to your list of plugins and restart the terminal.
    plugins=(... , activatevenv)
    ```

    ### Manually
    1. Simply copy and paste the script to the bottom of your `~/.bashrc` or `~/.zshrc` and restart your terminal.


    ## Usage
    For existing projects, simply `cd` into your any directory that contains either a `venv/`, `.venv/` virtualenv created and the script will activate it automatically (Just as you would do with source ./venv/bin/activate)
    If you are creating a new virtualenv run `python -m <venv|virtualenv> <venv|.venv>` in your root directory and to activate it manually use call `activatevenv` (or if you cd back into your project it will automatically activate it without the need of calling activatevenv).
    2 changes: 0 additions & 2 deletions activatevenv.sh → activatevenv.plugin.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    # Copy and paste these lines into your ~/.zshrc and restart the terminal.

    # Automatically activates venv if ./venv/ exists in curent directory
    # Go to your project folder, run "pip virtualenv <.venv|venv>", so your project folder
    # has a <.venv|venv> folder at the top level
  9. @kishannareshpal kishannareshpal revised this gist Dec 18, 2020. No changes.
  10. @kishannareshpal kishannareshpal revised this gist Dec 18, 2020. No changes.
  11. @kishannareshpal kishannareshpal revised this gist Dec 18, 2020. No changes.
  12. @kishannareshpal kishannareshpal created this gist Dec 18, 2020.
    39 changes: 39 additions & 0 deletions activatevenv.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    # Copy and paste these lines into your ~/.zshrc and restart the terminal.

    # Automatically activates venv if ./venv/ exists in curent directory
    # Go to your project folder, run "pip virtualenv <.venv|venv>", so your project folder
    # has a <.venv|venv> folder at the top level
    # .
    # ├── <other_project_files>
    # ├── ...
    # └── <.venv|venv>
    # ├── bin
    # ├── include
    # └── lib
    #
    # The virtualenv will be activated automatically when you enter the directory.
    # To deactivate run `deactivate` and to manually activate run `activatevenv`
    function activatevenv() {
    # Names of possible virtualenv directories
    VIRTUALENV_DIRS=("venv/" ".venv/" "${PWD##*/}")

    for dir in $VIRTUALENV_DIRS; do
    if [[ -d "${dir}" ]]; then
    # Found a possible venv directory
    # Try activating the venv
    if [[ -e "./${dir}/bin/activate" ]]; then
    source ./$dir/bin/activate
    echo "Virtual environment activated automatically"
    fi
    fi
    done

    }
    activatevenv

    # Extension for `cd` command in order to automatically acticate virtualenv
    function cd() {
    builtin cd $1
    # Try activating venv
    activatevenv
    }