Add autoenv add=py to streamline virtualenvs
This commit is contained in:
parent
4252d06e65
commit
908ef3efa5
@ -16,6 +16,7 @@ _autoenv() {
|
||||
init:'add .enter and .exit scripts in current directory'
|
||||
edit:'edit .enter and .exit scripts in current directory'
|
||||
deinit:'remove .enter and .exit scripts in current directory'
|
||||
add=py:'add Python virtualenv to the autoenv'
|
||||
)
|
||||
_describe -t commands command commands && ret=0 ;;
|
||||
esac
|
||||
|
@ -20,21 +20,25 @@ options:
|
||||
commands:
|
||||
init add .enter and .exit scripts in current directory
|
||||
edit edit .enter and .exit scripts in current directory
|
||||
deinit remove .enter and .exit scripts in current directory"
|
||||
deinit remove .enter and .exit scripts in current directory
|
||||
add=py add Python virtualenv to the autoenv"
|
||||
;;
|
||||
|
||||
init) # Create .enter and .exit scripts in current directory.
|
||||
if [ -f $PWD/.enter ] || [ -f $PWD/.exit ]; then
|
||||
echo '.enter or .exit already exists'; return 1
|
||||
fi
|
||||
# Create then edit .enter and .exit scripts.
|
||||
touch .enter .exit && autoenv edit
|
||||
# Create the .enter and .exit scripts.
|
||||
touch .enter .exit
|
||||
# If enter script exists, authorize it.
|
||||
[ -f $PWD/.enter ] && _autoenv_authorized $PWD/.enter yes
|
||||
# If exit script exists, authorize it.
|
||||
[ -f $PWD/.exit ] && _autoenv_authorized $PWD/.exit yes
|
||||
# Edit the autoenv.
|
||||
autoenv edit
|
||||
# Enter the autoenv.
|
||||
_autoenv_enter $PWD ;;
|
||||
_autoenv_enter $PWD
|
||||
;;
|
||||
|
||||
edit) # Edit .enter and .exit scripts in current directory.
|
||||
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
|
||||
@ -54,32 +58,47 @@ commands:
|
||||
_autoenv_enter $PWD
|
||||
else
|
||||
echo 'vim not found'; return 1
|
||||
fi ;;
|
||||
fi
|
||||
;;
|
||||
|
||||
deinit) # Remove .enter and .exit scripts in current directory.
|
||||
if [ -f $PWD/.enter ] || [ -f $PWD/.exit ]; then
|
||||
# Prompt user to confirm removal of enter and exit scripts.
|
||||
while true; do
|
||||
read "answer?Are you sure [y/N]? "
|
||||
case "$answer" in
|
||||
y|Y|yes)
|
||||
# Exit the autoenv.
|
||||
_autoenv_exit $PWD
|
||||
# Remove enter and exit scripts if they exist.
|
||||
[ -f $PWD/.enter ] && rm $PWD/.enter
|
||||
[ -f $PWD/.exit ] && rm $PWD/.exit
|
||||
break ;;
|
||||
*) break ;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
echo '.enter and .exit not found'; return 1
|
||||
fi ;;
|
||||
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
|
||||
echo '.enter or .exit not found'; return 1
|
||||
fi
|
||||
# Prompt user to confirm removal of enter and exit scripts.
|
||||
while true; do
|
||||
read "answer?Are you sure [y/N]? "
|
||||
case "$answer" in
|
||||
y|Y|yes)
|
||||
# Exit the autoenv.
|
||||
_autoenv_exit $PWD
|
||||
# Remove enter and exit scripts if they exist.
|
||||
[ -f $PWD/.enter ] && rm $PWD/.enter
|
||||
[ -f $PWD/.exit ] && rm $PWD/.exit
|
||||
break ;;
|
||||
*) break ;;
|
||||
esac
|
||||
done
|
||||
;;
|
||||
|
||||
add=py) # Add Python virtualenv to the sandbox
|
||||
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
|
||||
echo '.enter or .exit not found'; return 1
|
||||
fi
|
||||
_autoenv_exit $PWD
|
||||
virtualenv .local
|
||||
echo 'source .local/bin/activate' >> .enter
|
||||
echo 'deactivate' >> .exit
|
||||
_autoenv_authorized $PWD/.enter yes
|
||||
_autoenv_authorized $PWD/.exit yes
|
||||
_autoenv_enter $PWD
|
||||
;;
|
||||
|
||||
*) # Invalid arguments, show help then error.
|
||||
echo "invalid arguments: $@"
|
||||
autoenv --help
|
||||
return 1 ;;
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user