From 5a33d2b5aca8b222aac199e78b8c043b3fcf4206 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Wed, 26 Oct 2022 20:29:56 +0100 Subject: [PATCH] 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`. --- autoenv/_autoenv | 1 + autoenv/autoenv.zsh | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/autoenv/_autoenv b/autoenv/_autoenv index d852e02..fec9781 100644 --- a/autoenv/_autoenv +++ b/autoenv/_autoenv @@ -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 ;; diff --git a/autoenv/autoenv.zsh b/autoenv/autoenv.zsh index 34caf74..5e2084b 100644 --- a/autoenv/autoenv.zsh +++ b/autoenv/autoenv.zsh @@ -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