55 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable file
		
	
	
	
	
| #!/bin/zsh
 | |
| 
 | |
| zparseopts -D -E c=cdhere -cdvenv=cdvenv h=help -help=help n=newvenv -new=newvenv t=tmsu -tmsu=tmsu
 | |
| if [[ -n $help ]]; then
 | |
| 	<<-HELP
 | |
| 	Usage: ${0:t} [-c] [DIR]
 | |
| 	       ${0:t} -t
 | |
| 
 | |
| 	If DIR contains bin/activate, start a shell with that virtualenv.
 | |
| 	Otherwise recursively look up virtualenvs in DIR (by looking for dirs ending
 | |
| 	in "venv") and select one with fzf.
 | |
| 
 | |
| 	 -c, --cdvenv  Change to the venv directory instead of going back to the 
 | |
| 	               current working directory
 | |
| 	 -t, --tmsu    list only venvs in a directory with tmsu tag lang=python
 | |
| 	HELP
 | |
| 	exit
 | |
| fi
 | |
| 
 | |
| ORIGDIR=$PWD
 | |
| 
 | |
| venvsh() {
 | |
| 	cd $1
 | |
| 	. bin/activate
 | |
| 	if [[ -z $cdvenv ]]; then
 | |
| 		cd $ORIGDIR
 | |
| 	fi
 | |
| 	$SHELL
 | |
| }
 | |
| 
 | |
| if [[ -n $tmsu ]]; then
 | |
| 	venv=$(
 | |
| 		for i in $(tmsu files --directory lang=python); do
 | |
| 			[[ -d $i/venv ]] && echo $i/venv
 | |
| 		done | fzf)
 | |
| 	if [[ -n $venv ]]; then
 | |
| 		exec venvsh $venv
 | |
| 	else
 | |
| 		exit 1
 | |
| 	fi
 | |
| fi
 | |
| 
 | |
| if [[ -n $newvenv ]]; then
 | |
| 	python -mvenv ${1:-venv}
 | |
| 	exec venvsh ${1:-venv}
 | |
| fi
 | |
| 
 | |
| if [[ -n $1 && -e $1/bin/activate ]]; then
 | |
| 	exec venvsh $1
 | |
| fi
 | |
| 
 | |
| venv=$(fd -I -t d 'venv$' $1 | fzf)
 | |
| if [[ -n $venv ]]; then
 | |
| 	exec venvsh $venv
 | |
| fi
 | 
