# Little "alias" function for 'source venv/bin/activate'

**URL:** <https://forum.endeavouros.com/t/little-alias-function-for-source-venv-bin-activate/75220>\
**Category:** Community contributions\
**Created:** [September 20, 2025, 4:05am UTC](https://forum.endeavouros.com/t/little-alias-function-for-source-venv-bin-activate/75220 "2025-09-20T04:05:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spreadneck](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/spreadneck/32/109924_2.png) [@Spreadneck](https://forum.endeavouros.com/u/Spreadneck)\
**Post date:** [September 20, 2025, 4:05am UTC](https://forum.endeavouros.com/t/little-alias-function-for-source-venv-bin-activate/75220/1 "2025-09-20T04:05:43Z")

</div>

@mods  
I don’t see a coding or scripting sub forum here so just posting this here if any one wants to use it. Delete if necessary.

I just put it into my .bashrc and run by `venv_activate`, or make it a bash script and put into your `$PATH`

replaces `source venv/bin/activate` or `source .venv/bin/activate`

```auto
venv_activate() {
    if [-f .venv/bin/activate]; then
        echo "Activating virtual environment from: .venv in $PWD"
        echo -e "Enjoy working on the $(basename "$PWD") project, ${USER^}!"
        source .venv/bin/activate
    # If not found, check for a venv directory
    elif [-f venv/bin/activate]; then
        echo "Activating virtual environment from: venv in $PWD"
        echo -e "Enjoy working on the $(basename "$PWD") project, ${USER^}!"
        source venv/bin/activate
    else
        echo "Error: No 'venv' or '.venv' directory found." >&2
        return 1
    fi
}

```

---

<div class="post-metadata">

**Author:** ![Shawncrook](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/s/51bf81/32.png) [@Shawncrook](https://forum.endeavouros.com/u/Shawncrook)\
**Post date:** [September 20, 2025, 7:14am UTC](https://forum.endeavouros.com/t/little-alias-function-for-source-venv-bin-activate/75220/2 "2025-09-20T07:14:16Z")

</div>

A neat shortcut. Adding the project name into the echo message is a nice touch—makes it clear which environment is currently active.

---

<div class="post-metadata">

**Author:** ![Spreadneck](https://forum.endeavouros.com/user_avatar/forum.endeavouros.com/spreadneck/32/109924_2.png) [@Spreadneck](https://forum.endeavouros.com/u/Spreadneck)\
**Post date:** [September 20, 2025, 12:40pm UTC](https://forum.endeavouros.com/t/little-alias-function-for-source-venv-bin-activate/75220/4 "2025-09-20T12:40:11Z")

</div>

Made a better one. Little more color. I’m still kinda newish to scripts, but now I can’t stop writting them though. #geekfun

```bash
#!/bin/bash

Color_Off='\033[0m'
BGreen='\033[1;32m'
nl=$'\n'

venv_activate() {
    enjoy() {
        echo -e "Enjoy working on your $(basename "$PWD") project, ${USER^}!"
        printf '*%.0s' {1..80}

    }

   spin_up() {
        if [-n "$1"]; then #Check if a virtual environment path is provided.
            bash -c "source $1/bin/activate; exec bash -i" || echo "Failed to activate: $1"
        else
            echo "Error: No virtual environment path provided to spin_up." >&2
            return 1
        fi
    }

    if [-d "$PWD/.venv"]; then ${nl}
        printf '*%.0s' {1..80}
        echo -e "${nl}$BGreen .venv$Color_Off found in: $PWD | $BGreen .venv$Color_Off activated.${nl}"
        venv_path="$PWD/.venv"
        enjoy
        spin_up "$venv_path"
        return 0
    elif [-d "$PWD/venv"]; then
        printf '*%.0s' {1..80}
        echo -e "${nl}$BGreen venv$Color_Off found in: $PWD | $BGreen venv$Color_Off activated.${nl}"
        venv_path="$PWD/venv"
        enjoy
        spin_up "$venv_path"
        return 0
    else
        echo -e "Error: No 'venv' or '.venv' directory found." >&2
        return 1  
    fi

}

venv_activate

```
