autoenv: Automatically update autoenv during edit
Fixes #18 by exiting the autoenv before invoking vim for editing the `.enter` and `.exit` scripts, then enters the autoenv after vim exits. This reduces the number of steps required to update the current autoenv state.
This commit is contained in:
parent
0da54801e4
commit
7a0c73dabb
@ -23,37 +23,48 @@ commands:
|
||||
deinit remove .enter and .exit scripts in current directory"
|
||||
;;
|
||||
|
||||
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
|
||||
echo '.enter or .exit already exists'; return 1
|
||||
fi
|
||||
# Create then edit enter and exit scripts.
|
||||
# Create then edit .enter and .exit scripts.
|
||||
touch .enter .exit && autoenv edit
|
||||
# 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
|
||||
# Enter the new autoenv.
|
||||
# Enter the autoenv.
|
||||
_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
|
||||
echo '.enter or .exit not found'; return 1
|
||||
fi
|
||||
# If vim exists, edit enter and exit scripts.
|
||||
if which vim &> /dev/null; then
|
||||
vim -p $PWD/.enter $PWD/.exit
|
||||
# Exit the autoenv before editing.
|
||||
_autoenv_exit $PWD
|
||||
if vim -p $PWD/.enter $PWD/.exit; then
|
||||
# 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
|
||||
fi
|
||||
# Enter the autoenv.
|
||||
_autoenv_enter $PWD
|
||||
else
|
||||
echo 'vim not found'; return 1
|
||||
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
|
||||
# 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user