Skip to content

Instantly share code, notes, and snippets.

@aleccedwards
aleccedwards / python
Last active February 22, 2021 13:39
Bash-completion for user python modules. Replace /usr/share/bash-completion/completions/python with this (note only changed lines are 5 and 6).
# bash completion for python -*- shell-script -*-
_python_modules()
{
opts="$(find . -name '*.py' -type f | sed 's+/+.+g' | sed 's/^\..//' | sed 's/\.[^.]*$//' | head -n -0)"
COMPREPLY+=($(compgen -W "$opts" -- "$cur"))
COMPREPLY+=( $(compgen -W \
"$(${1:-python} ${BASH_SOURCE[0]%/*}/../helpers/python $cur \
2>/dev/null)" -- "$cur") )
@aleccedwards
aleccedwards / pysource.sh
Last active February 22, 2021 13:38
Pysource - bash function for ~/.bashrc to help activate virtual environments stored in a common directory
function pysource() {
# Doesn't work with venvs called ls
# Change directory at will
if [ $1 == 'ls' ]
then
ls ~/.venvs
else
source ~/.venvs/$1/bin/activate
fi