Files
scwrypts/zsh/scwrypts/environment/edit
yage eaefc99774 v2.0.0
=====================================================================

Subscwrypts + Environment Inheritance

--- Release Notes ------------------------

- added support for environment inheritance
- added support for arbitrarily nested scripts (subscwrypts)
- added support for CI mode

- improved modularity of zsh/utils module

- refactored to move some data from ~/.config/scwrypts to ~/.local/share/scwrypts

- refactored various scripts to use new subscwrypt api

--- New Scripts --------------------------

zsh )
  - db/interactive/postgres
  - aws/rds/interactive-login
2022-07-01 22:17:15 -06:00

45 lines
1.2 KiB
Bash
Executable File

#!/bin/zsh
_DEPENDENCIES+=()
_REQUIRED_ENV+=()
source ${0:a:h}/common.zsh
#####################################################################
[ $1 ] && ENV_NAME="$1"
[ ! $1 ] && {
[ $SCWRYPTS_ENV ] \
&& ENV_NAME=$SCWRYPTS_ENV \
|| ENV_NAME=$(__SELECT_OR_CREATE_ENV)
}
[ ! $ENV_NAME ] && __ABORT
ENV_FILE=$(__GET_ENV_FILE $ENV_NAME)
[ ! -f $ENV_FILE ] && {
__STATUS "Creating '$ENV_NAME'..." \
&& cp $__ENV_TEMPLATE $ENV_FILE \
&& __SUCCESS 'created!' \
|| { __ERROR "failed to create '$ENV_FILE'"; exit 1; }
}
__STATUS "opening '$ENV_NAME' for editing..."
__EDIT $ENV_FILE
sed -i "s/^[A-Z]/export &/; s/^[^#=]\\+$/&=/" $ENV_FILE
LC_COLLATE=C sort -uo $ENV_FILE $ENV_FILE
__STATUS "finished editing; looking for new environment variables"
while read line
do
ENV_VAR=$(echo "$line" | sed 's/=.*$//; s/^export //')
grep -q "$ENV_VAR" $__ENV_TEMPLATE || {
((NEW_VAR+=1))
echo "export $ENV_VAR=" >> $__ENV_TEMPLATE
__STATUS "detected new variable '$ENV_VAR'"
}
done < $ENV_FILE
__RUN_SCWRYPT zsh/scwrypts/environment/synchronize -- --no-prompt \
|| __FAIL 4 'failed to run environment sync' \
;
__SUCCESS "environment '$ENV_NAME' successfully modified"