Add autoenv add=local subcommand
The `add=local` subcommand creates `.local/bin` if it doesn't exit and then updates the autoenv to add it to `PATH`.
This commit is contained in:
parent
c691d335c0
commit
5a33d2b5ac
@ -17,6 +17,7 @@ _autoenv() {
|
||||
edit:'edit .enter and .exit scripts in current directory'
|
||||
deinit:'remove .enter and .exit scripts in current directory'
|
||||
reload:'reload the current environment'
|
||||
add=local:'add .local/bin to PATH'
|
||||
add=py:'add Python virtualenv to the autoenv'
|
||||
)
|
||||
_describe -t commands command commands && ret=0 ;;
|
||||
|
@ -22,6 +22,7 @@ commands:
|
||||
edit edit .enter and .exit scripts in current directory
|
||||
deinit remove .enter and .exit scripts in current directory
|
||||
reload reload the current environment
|
||||
add=local add .local/bin to PATH
|
||||
add=py add Python virtualenv to the autoenv"
|
||||
;;
|
||||
|
||||
@ -92,6 +93,27 @@ commands:
|
||||
_autoenv_enter $PWD
|
||||
;;
|
||||
|
||||
add=local) # Add .local/bin to PATH
|
||||
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
|
||||
echo '.enter or .exit not found'; return 1
|
||||
fi
|
||||
_autoenv_exit $PWD
|
||||
# Create .local/bin if not present
|
||||
if ! [ -d $PWD/.local/bin ]; then
|
||||
mkdir -p $PWD/.local/bin
|
||||
fi
|
||||
# On enter: store PATH and insert .local/bin
|
||||
echo 'OLDPATH=$PATH' >> .enter
|
||||
echo 'PATH=$PWD/.local/bin:$PATH' >> .enter
|
||||
# On exit: reset PATH
|
||||
echo 'PATH=$OLDPATH' >> .exit
|
||||
echo 'unset OLDPATH' >> .exit
|
||||
# Authorize modified autoenv
|
||||
_autoenv_authorized $PWD/.enter yes
|
||||
_autoenv_authorized $PWD/.exit yes
|
||||
_autoenv_enter $PWD
|
||||
;;
|
||||
|
||||
add=py) # Add Python virtualenv to the sandbox
|
||||
if ! [ -f $PWD/.enter ] || ! [ -f $PWD/.exit ]; then
|
||||
echo '.enter or .exit not found'; return 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user