Skip to content

Instantly share code, notes, and snippets.

@davidbgk
Created December 15, 2021 15:09
Show Gist options
  • Save davidbgk/51f38d1fc4ecc0c8778a9bab2804beb9 to your computer and use it in GitHub Desktop.
Save davidbgk/51f38d1fc4ecc0c8778a9bab2804beb9 to your computer and use it in GitHub Desktop.
Example of Python aliases + reimplementation of `cd` to auto de/activate the current virtualenv
# aliases
alias -g ll='ls -al'
alias -g subl='open -a "Sublime Text"'
alias server='python3 -m http.server 8000 --bind 127.0.0.1'
alias rmvenv='deactivate && rm -rf venv/'
alias venv='python3 -m venv venv'
alias activate='source venv/bin/activate'
alias pipupgrade='python3 -m pip install --upgrade pip'
alias requirements='python3 -m pip install -r requirements.txt'
# python virtualenv auto de/activation
function cd() {
if [[ -d ./venv ]] ; then
deactivate
fi
builtin cd $1
if [[ -d ./venv ]] ; then
. ./venv/bin/activate
fi
# also add node_modules/.bin to $PATH
if [[ -d ./node_modules ]] ; then
export PATH="$(npm bin):$PATH"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment