=====================================================================

--- Changes ------------------------------

- improved colors readability by naming color variables in zsh/utils

--- Bug Fixes ----------------------------

- aws/efs/mount wouldn't mount if the previous session was not
  explicitly unmounted. now it does :)
This commit is contained in:
Wryn (yage) Wagner 2022-07-01 20:57:03 -06:00
parent f30eb7fb9e
commit db0d0092db
6 changed files with 50 additions and 28 deletions

View File

@ -12,7 +12,7 @@ __RUN() {
while [[ $# -gt 0 ]]
do
case $1 in
-e|--env )
-e | --env )
[ $ENV_NAME ] && __WARNING 'overwriting session environment'
ENV_NAME="$2"
__STATUS "using CLI environment '$ENV_NAME'"
@ -196,8 +196,7 @@ __VALIDATE_UPSTREAM_TIMELINE() {
__GET_LOGFILE() {
local SCRIPT="$1"
[ $CI ] \
|| [ $SUBSCWRYPT ] \
[ $SUBSCWRYPT ] \
|| [[ $SCRIPT =~ scwrypts/logs ]] \
|| [[ $SCRIPT =~ interactive ]] \
&& return 0

View File

@ -19,6 +19,7 @@ _EFS_CONNECT() {
[ ! $FS_ID ] && __ABORT
local MOUNT_POINT="$AWS__EFS__LOCAL_MOUNT_POINT/$FS_ID"
[ -d "$MOUNT_POINT" ] && sudo rmdir "$MOUNT_POINT" >/dev/null 2>&1
[ -d "$MOUNT_POINT" ] && {
__STATUS "$FS_ID is already mounted"
exit 0

View File

@ -55,17 +55,3 @@ _REQUIRED_ENV+=(
source ./path/to/utils.plugin.zsh
echo "missing $ENV_ERROR_COUNT required environment variables"
```
io.zsh
os.zsh
## Basic Utilities
One of my biggest pet-peeves with scripting is when every line of a *(insert-language-here)* program is escaped to shell.
This kind of program, which doesn't use language features, should be a shell script.
While there are definitely unavoidable limitations to shell scripting, we can minimize a variety of problems with a modern shell and shared utilities library.
Loaded by `common.zsh`, the [`utils/` library](./utils) provides:
- common function wrappers to unify flags and context
- lazy dependency and environment variable validation
- consistent (and pretty) user input / output

25
zsh/utils/colors.zsh Normal file
View File

@ -0,0 +1,25 @@
__BLACK='\033[0;30m'
__DARK_GRAY='\033[1;30m'
__RED='\033[0;31m'
__LIGHT_RED='\033[1;31m'
__GREEN='\033[0;32m'
__LIGHT_GREEN='\033[1;32m'
__ORANGE='\033[0;33m'
__YELLOW='\033[1;33m'
__BLUE='\033[1;34m'
__DARK_BLUE='\033[0;34m'
__PURPLE='\033[1;35m'
__DARK_PURPLE='\033[0;35m'
__CYAN='\033[1;36m'
__DARK_CYAN='\033[0;36m'
__WHITE='\033[1;37m'
__LIGHT_GRAY='\033[0;37m'
__COLOR_RESET='\033[0m'

View File

@ -1,14 +1,28 @@
__ERROR() { echo "\\033[1;31mERROR ✖ : $@\\033[0m" >&2; }
__SUCCESS() { echo "\\033[1;32mSUCCESS ✔ : $@\\033[0m" >&2; }
__WARNING() { echo "\\033[1;33mWARNING  : $@\\033[0m" >&2; }
__STATUS() { echo "\\033[1;34mSTATUS : $@\\033[0m" >&2; }
__REMINDER() { echo "\\033[1;35mREMINDER  : $@\\033[0m" >&2; }
__PRINT() {
local COLOR="$1"
local MESSAGE="$2"
local LINE_END
[ $3 ] && LINE_END='' || LINE_END='\n'
printf "${COLOR}${MESSAGE}${__COLOR_RESET}${LINE_END}"
}
__ERROR() { __PRINT $__RED "ERROR ✖ : $@" >&2; }
__SUCCESS() { __PRINT $__GREEN "SUCCESS ✔ : $@" >&2; }
__WARNING() { __PRINT $__ORANGE "WARNING  : $@" >&2; }
__STATUS() { __PRINT $__BLUE "STATUS : $@" >&2; }
__REMINDER() { __PRINT $__PURPLE "REMINDER  : $@" >&2; }
__INFO() { __PRINT $__WHITE "INFO  : $@" >&2; }
__PROMPT() {
echo "\\033[1;36mPROMPT  : $@\\033[0m" >&2
printf "\\033[1;36mUSER  : \\033[0m" >&2
__PRINT $__CYAN "PROMPT  : $@" >&2
__PRINT $__CYAN "USER  : " --no-end >&2
}
__FAIL() { __ERROR "${@:2}"; exit $1; }
__ABORT() { __FAIL 69 'user abort'; }
__Yn() {
__PROMPT "$@ [Yn]"
[ $CI ] && { echo y; return 0; }
@ -25,10 +39,6 @@ __yN() {
[[ $yN =~ [yY] ]] && return 0 || return 1
}
__FAIL() { __ERROR "${@:2}"; exit $1; }
__ABORT() { __FAIL 69 'user abort'; }
#####################################################################
__GETSUDO() {

View File

@ -5,6 +5,7 @@ _REQUIRED_ENV+=() # (extensible) list of required environment variables
#####################################################################
source ${0:a:h}/colors.zsh
source ${0:a:h}/io.zsh
source ${0:a:h}/os.zsh
source ${0:a:h}/credits.zsh