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'
|
init:'add .enter and .exit scripts in current directory'
|
||||||
edit:'edit .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'
|
||||||
)
|
)
|
||||||
_describe -t commands command commands && ret=0 ;;
|
_describe -t commands command commands && ret=0 ;;
|
||||||
esac
|
esac
|
||||||
|
@ -20,21 +20,25 @@ options:
|
|||||||
commands:
|
commands:
|
||||||
init add .enter and .exit scripts in current directory
|
init add .enter and .exit scripts in current directory
|
||||||
edit edit .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.
|
init) # Create .enter and .exit scripts in current directory.
|
||||||
if [ -f $PWD/.enter ] || [ -f $PWD/.exit ]; then
|
if [ -f $PWD/.enter ] || [ -f $PWD/.exit ]; then
|
||||||
echo '.enter or .exit already exists'; return 1
|
echo '.enter or .exit already exists'; return 1
|
||||||
fi
|
fi
|
||||||
# Create then edit .enter and .exit scripts.
|
# Create the .enter and .exit scripts.
|
||||||
touch .enter .exit && autoenv edit
|
touch .enter .exit
|
||||||
# If enter script exists, authorize it.
|
# If enter script exists, authorize it.
|
||||||
[ -f $PWD/.enter ] && _autoenv_authorized $PWD/.enter yes
|
[ -f $PWD/.enter ] && _autoenv_authorized $PWD/.enter yes
|
||||||
# If exit script exists, authorize it.
|
# If exit script exists, authorize it.
|
||||||
[ -f $PWD/.exit ] && _autoenv_authorized $PWD/.exit yes
|
[ -f $PWD/.exit ] && _autoenv_authorized $PWD/.exit yes
|
||||||
|
# Edit the autoenv.
|
||||||
|
autoenv edit
|
||||||
# Enter the autoenv.
|
# Enter the autoenv.
|
||||||
_autoenv_enter $PWD ;;
|
_autoenv_enter $PWD
|
||||||
|
;;
|
||||||
|
|
||||||
edit) # Edit .enter and .exit scripts in current directory.
|
edit) # Edit .enter and .exit scripts in current directory.
|
||||||
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
|
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
|
||||||
@ -54,10 +58,13 @@ commands:
|
|||||||
_autoenv_enter $PWD
|
_autoenv_enter $PWD
|
||||||
else
|
else
|
||||||
echo 'vim not found'; return 1
|
echo 'vim not found'; return 1
|
||||||
fi ;;
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
deinit) # Remove .enter and .exit scripts in current directory.
|
deinit) # Remove .enter and .exit scripts in current directory.
|
||||||
if [ -f $PWD/.enter ] || [ -f $PWD/.exit ]; then
|
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.
|
# Prompt user to confirm removal of enter and exit scripts.
|
||||||
while true; do
|
while true; do
|
||||||
read "answer?Are you sure [y/N]? "
|
read "answer?Are you sure [y/N]? "
|
||||||
@ -72,14 +79,26 @@ commands:
|
|||||||
*) break ;;
|
*) break ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
else
|
;;
|
||||||
echo '.enter and .exit not found'; return 1
|
|
||||||
fi ;;
|
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.
|
*) # Invalid arguments, show help then error.
|
||||||
echo "invalid arguments: $@"
|
echo "invalid arguments: $@"
|
||||||
autoenv --help
|
autoenv --help
|
||||||
return 1 ;;
|
return 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user