From 6333a2f6b84c737a587257a50bcef7c2a8d75a19 Mon Sep 17 00:00:00 2001 From: yage Date: Mon, 15 Aug 2022 18:30:37 -0600 Subject: [PATCH] v2.5.0 ===================================================================== --- New Scripts -------------------------- zsh ) vundle-vim helpers - vim/vundle/edit-build-actions - vim/vundle/install - vim/vundle/rebuild quick install-from-source scripts - git/package/install - git/package/build (install --only-build) - git/package/download (install --only-pull) - git/package/update (install --update) config sym-linker (for source-controlled .configs) - config/update (symlinks + terminfo) - config/symlinks (set all symlinks from settings) - config/settings (edit settings which aren't scwrypts env variables) - config/terminfo (load all terminfo from settings) --- Changes ------------------------------ - helper comments are now inserted in all env files - removed underscore prefix for standard AWS environment variables - added "opening" and "finished editing" comments to __EDIT util - added __USAGE to format $USAGE variable to std:err - added __ERROR_CHECK to exit if any __ERROR(s) were called --- .env.template | 6 +- .env.template.descriptions | 12 ++++ README.md | 1 - global/common.zsh | 4 +- run | 25 ++++---- scwrypts | 2 +- zsh/aws/common.zsh | 8 +-- zsh/aws/ecr/login | 6 +- zsh/aws/rds/common.zsh | 7 ++- zsh/aws/route53/backup | 4 +- zsh/config/common.zsh | 13 ++++ zsh/config/default.conf.zsh | 19 ++++++ zsh/config/settings | 6 ++ zsh/config/symlinks | 36 ++++++++++++ zsh/config/terminfo | 26 ++++++++ zsh/config/update | 10 ++++ zsh/git/common.zsh | 6 ++ zsh/git/package/build | 6 ++ zsh/git/package/common.zsh | 73 +++++++++++++++++++++++ zsh/git/package/download | 6 ++ zsh/git/package/install | 88 ++++++++++++++++++++++++++++ zsh/git/package/update | 6 ++ zsh/memo/open | 2 - zsh/scwrypts/configure | 2 - zsh/scwrypts/environment/common.zsh | 1 + zsh/scwrypts/environment/edit | 8 +-- zsh/scwrypts/environment/synchronize | 23 ++++++++ zsh/utils/io.zsh | 27 ++++++++- zsh/utils/utils.module.zsh | 6 -- zsh/vim/common.zsh | 8 +++ zsh/vim/vundle/common.zsh | 49 ++++++++++++++++ zsh/vim/vundle/edit-build-actions | 6 ++ zsh/vim/vundle/install | 13 ++++ zsh/vim/vundle/rebuild | 6 ++ 34 files changed, 472 insertions(+), 49 deletions(-) create mode 100644 .env.template.descriptions create mode 100644 zsh/config/common.zsh create mode 100644 zsh/config/default.conf.zsh create mode 100755 zsh/config/settings create mode 100755 zsh/config/symlinks create mode 100755 zsh/config/terminfo create mode 100755 zsh/config/update create mode 100644 zsh/git/common.zsh create mode 100755 zsh/git/package/build create mode 100644 zsh/git/package/common.zsh create mode 100755 zsh/git/package/download create mode 100755 zsh/git/package/install create mode 100755 zsh/git/package/update create mode 100644 zsh/vim/common.zsh create mode 100644 zsh/vim/vundle/common.zsh create mode 100755 zsh/vim/vundle/edit-build-actions create mode 100755 zsh/vim/vundle/install create mode 100755 zsh/vim/vundle/rebuild diff --git a/.env.template b/.env.template index 29674a1..67cdaff 100644 --- a/.env.template +++ b/.env.template @@ -1,10 +1,10 @@ #!/bin/zsh +export AWS_ACCOUNT= +export AWS_PROFILE= +export AWS_REGION= export AWS__EFS__LOCAL_MOUNT_POINT= export AWS__S3__MEDIA_BUCKET= export AWS__S3__MEDIA_TARGETS= export REDIS_AUTH= export REDIS_HOST= export REDIS_PORT= -export _AWS_ACCOUNT= -export _AWS_PROFILE= -export _AWS_REGION= diff --git a/.env.template.descriptions b/.env.template.descriptions new file mode 100644 index 0000000..857de6f --- /dev/null +++ b/.env.template.descriptions @@ -0,0 +1,12 @@ +AWS_ACCOUNT | standard AWS environment variables used by awscli and other tools +AWS_PROFILE | +AWS_REGION | + +AWS__EFS__LOCAL_MOUNT_POINT | fully-qualified path to mount the EFS drive + +AWS__S3__MEDIA_BUCKET | s3 bucket name and filesystem targets for media backups +AWS__S3__MEDIA_TARGETS | + +REDIS_AUTH | redis connection credentials +REDIS_HOST | +REDIS_PORT | diff --git a/README.md b/README.md index 99d027a..4221043 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,6 @@ After determining which script to run, if no environment has been specified, Scw Set environment variable `CI=true` (and use the no install method) to run in an automated pipeline. There are a few notable changes to this runtime: - **The Scwrypts sandbox environment will not load.** All variables will be read from context. - - The underscore-prefixed `_AWS_(PROFILE|REGION|ACCOUNT)` variables will be read from the standard `AWS_` variables - User yes/no prompts will **always be YES** - Other user input will default to an empty string - Logs will not be captured diff --git a/global/common.zsh b/global/common.zsh index 25b597d..d4d907d 100644 --- a/global/common.zsh +++ b/global/common.zsh @@ -28,14 +28,14 @@ __GET_PATH_TO_RELATIVE_ARGUMENT() { __RUN_SCWRYPT() { ((SUBSCWRYPT+=1)) { printf ' '; printf '--%.0s' {1..$SUBSCWRYPT}; printf " ($SUBSCWRYPT) "; } >&2 - echo " BEGIN SUBSCWRYPT : $(basename $1)" >&2 + echo " BEGIN SUBSCWRYPT : $@" >&2 SUBSCWRYPT=$SUBSCWRYPT SCWRYPTS_ENV=$ENV_NAME \ "$SCWRYPTS_ROOT/scwrypts" $@ EXIT_CODE=$? { printf ' '; printf '--%.0s' {1..$SUBSCWRYPT}; printf " ($SUBSCWRYPT) "; } >&2 - echo " END SUBSCWRYPT : $(basename $1)" >&2 + echo " END SUBSCWRYPT : $1" >&2 ((SUBSCWRYPT-=1)) return $EXIT_CODE diff --git a/run b/run index 826c83d..96040ec 100755 --- a/run +++ b/run @@ -7,27 +7,27 @@ source "$SCWRYPTS_ROOT/zsh/common.zsh" || exit 42 __RUN() { local USAGE=' -Usage : scwrypts [OPTIONS ...] SCRIPT -- [SCRIPT OPTIONS ...] + usage: scwrypts [OPTIONS ...] SCRIPT -- [SCRIPT OPTIONS ...] -OPTIONS - -e, --env set environment; overwrites SCWRYPTS_ENV - -n, --no-log skip logging (useful when calling scwrypts as an api) - -l, --list print out command list and exit + OPTIONS + -e, --env set environment; overwrites SCWRYPTS_ENV + -n, --no-log skip logging (useful when calling scwrypts as an api) + -l, --list print out command list and exit - -h, --help display this message and exit -' + -h, --help display this message and exit + ' cd "$SCWRYPTS_ROOT" local ENV_NAME="$SCWRYPTS_ENV" local SEARCH_PATTERNS=() - local ARGS_ERROR=0 + local ERROR=0 while [[ $# -gt 0 ]] do case $1 in -h | --help ) - echo $USAGE + __USAGE return 0 ;; -n | --no-log ) @@ -50,7 +50,6 @@ OPTIONS ;; -* ) __ERROR "unrecognized argument '$1'" - ((ARGS_ERROR+=1)) shift 1 ;; * ) @@ -60,15 +59,13 @@ OPTIONS esac done - [[ $ARGS_ERROR -gt 0 ]] && { - echo $USAGE - return 1 - } + __ERROR_CHECK ########################################## local SCRIPT=$(__SELECT_SCRIPT $SEARCH_PATTERNS) [ ! $SCRIPT ] && exit 2 + export SCWRYPT_NAME=$SCRIPT local ENV_REQUIRED=$(__CHECK_ENV_REQUIRED && echo 1 || echo 0) diff --git a/scwrypts b/scwrypts index 126270a..9f7f24d 100755 --- a/scwrypts +++ b/scwrypts @@ -1,2 +1,2 @@ #!/bin/zsh -source "${0:a:h}/run" +source "${0:a:h}/run" $@ diff --git a/zsh/aws/common.zsh b/zsh/aws/common.zsh index d8be006..8e1daf7 100644 --- a/zsh/aws/common.zsh +++ b/zsh/aws/common.zsh @@ -3,11 +3,11 @@ _DEPENDENCIES+=( jq ) _REQUIRED_ENV+=( - _AWS_ACCOUNT - _AWS_PROFILE - _AWS_REGION + AWS_ACCOUNT + AWS_PROFILE + AWS_REGION ) source ${0:a:h}/../common.zsh ##################################################################### -_AWS() { aws --profile $_AWS_PROFILE --region $_AWS_REGION --output json $@; } +_AWS() { aws --profile $AWS_PROFILE --region $AWS_REGION --output json $@; } diff --git a/zsh/aws/ecr/login b/zsh/aws/ecr/login index 330c50e..29053f0 100755 --- a/zsh/aws/ecr/login +++ b/zsh/aws/ecr/login @@ -9,6 +9,6 @@ __STATUS "performing AWS ECR docker login" _AWS ecr get-login-password | docker login \ --username AWS \ --password-stdin \ - "$_AWS_ACCOUNT.dkr.ecr.$_AWS_REGION.amazonaws.com" \ - && __SUCCESS "logged in to 'AWS:$_AWS_ACCOUNT:$_AWS_REGION'" \ - || __FAIL 1 "unable to login to '$_AWS_ACCOUNT' in '$_AWS_REGION'" + "$AWS_ACCOUNT.dkr.ecr.$AWS_REGION.amazonaws.com" \ + && __SUCCESS "logged in to 'AWS:$AWS_ACCOUNT:$AWS_REGION'" \ + || __FAIL 1 "unable to login to '$AWS_ACCOUNT' in '$AWS_REGION'" diff --git a/zsh/aws/rds/common.zsh b/zsh/aws/rds/common.zsh index 5760f0b..c87857f 100644 --- a/zsh/aws/rds/common.zsh +++ b/zsh/aws/rds/common.zsh @@ -5,7 +5,7 @@ source ${0:a:h}/../common.zsh GET_DATABASE_CREDENTIALS() { local PRINT_PASSWORD=0 - local ARGS_ERRORS=0 + local ERRORS=0 while [[ $# -gt 0 ]] do @@ -13,12 +13,13 @@ GET_DATABASE_CREDENTIALS() { --print-password ) PRINT_PASSWORD=1 ;; * ) __WARNING "unrecognized argument $1" - ARGS_ERRORS+=1 + ERRORS+=1 ;; esac shift 1 done - [[ $ARGS_ERRORS -ne 0 ]] && return 1 + + __ERROR_CHECK ########################################## diff --git a/zsh/aws/route53/backup b/zsh/aws/route53/backup index 1275a61..b6df8a7 100755 --- a/zsh/aws/route53/backup +++ b/zsh/aws/route53/backup @@ -13,7 +13,7 @@ _ROUTE53_BACKUP() { for DOMAIN in $(_ROUTE53_GET_DOMAINS) do ( __STATUS "creating '$BACKUP_PATH/$DOMAIN.txt'" \ - && cli53 export --profile $_AWS_PROFILE $DOMAIN > "$BACKUP_PATH/$DOMAIN.txt" \ + && cli53 export --profile $AWS_PROFILE $DOMAIN > "$BACKUP_PATH/$DOMAIN.txt" \ && __SUCCESS "backed up '$DOMAIN'" \ || __ERROR "failed to back up '$DOMAIN'" \ ) & @@ -25,7 +25,7 @@ _ROUTE53_BACKUP() { } _ROUTE53_GET_DOMAINS() { - cli53 list --profile $_AWS_PROFILE \ + cli53 list --profile $AWS_PROFILE \ | awk '{print $2;}' \ | sed '1d; s/\.$//'\ ; diff --git a/zsh/config/common.zsh b/zsh/config/common.zsh new file mode 100644 index 0000000..62cd08f --- /dev/null +++ b/zsh/config/common.zsh @@ -0,0 +1,13 @@ +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +DEFAULT_CONFIG="${0:a:h}/default.conf.zsh" +source ${0:a:h}/../common.zsh +##################################################################### + +SAFE_SYMLINKS=1 + +# in case config.dotfile.zsh is sourced... allow user to provide initial config ;) +[ ! $CONFIG__USER_SETTINGS ] \ + && CONFIG__USER_SETTINGS="$SCWRYPTS_CONFIG_PATH/config.dotfile.zsh" +[ ! -f "$CONFIG__USER_SETTINGS" ] && cp "$DEFAULT_CONFIG" "$CONFIG__USER_SETTINGS" +source $CONFIG__USER_SETTINGS diff --git a/zsh/config/default.conf.zsh b/zsh/config/default.conf.zsh new file mode 100644 index 0000000..1e29f1c --- /dev/null +++ b/zsh/config/default.conf.zsh @@ -0,0 +1,19 @@ +# +# scwrypts dot-files config +# + +#TERMINFO_PATH=/path/to/sourced/terminfo/files + +# +# SAFE_SYMLINKS=1, makes a backup of config files that already exist +# SAFE_SYMLINKS=0, deletes existing config file +# +#SAFE_SYMLINKS=1 + + +# lines which begin with '#' are ignored +SYMLINKS=" +# fully qualified path ~/.config/THE-REST +# --------------------------------------------- +# /path/to/your/kitty.conf kitty/kitty.conf +" diff --git a/zsh/config/settings b/zsh/config/settings new file mode 100755 index 0000000..1fe07f6 --- /dev/null +++ b/zsh/config/settings @@ -0,0 +1,6 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### +__EDIT "$CONFIG__USER_SETTINGS" diff --git a/zsh/config/symlinks b/zsh/config/symlinks new file mode 100755 index 0000000..f1dc0e6 --- /dev/null +++ b/zsh/config/symlinks @@ -0,0 +1,36 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### + +SETUP_SYMLINKS() { + while read SYMLINK + do + SETUP_SYMLINK $(echo $SYMLINK | awk '{print $1;}') $(echo $SYMLINK | awk '{print $2}') + done < <(echo $SYMLINKS | sed -n '/^[^#]/p') +} + +SETUP_SYMLINK() { + [ ! $2 ] && __FAIL 1 'must provide SOURCE_CONFIG and TARGET_CONFIG' + + local SOURCE_CONFIG="$1" + [ ! -f "$SOURCE_CONFIG" ] && __FAIL 2 "no such file '$SOURCE_CONFIG'" + + local TARGET_CONFIG="$HOME/.config/$2" + + [ ! -d $(dirname "$TARGET_CONFIG") ] && mkdir -p $(dirname "$TARGET_CONFIG") + + [ -f "$TARGET_CONFIG" ] && { + [[ $SAFE_SYMLINKS -eq 1 ]] && mv "$TARGET_CONFIG" "$TARGET_CONFIG.bak" + [[ $SAFE_SYMLINKS -eq 0 ]] && rm "$TARGET_CONFIG" + } + + ln -s "$SOURCE_CONFIG" "$TARGET_CONFIG" \ + && __SUCCESS "successfully linked '$(basename $(dirname $TARGET_CONFIG))/$(basename $TARGET_CONFIG)'" \ + || __FAIL 3 "failed to create link '$TARGET_CONFIG'" \ + ; +} + +##################################################################### +SETUP_SYMLINKS $@ diff --git a/zsh/config/terminfo b/zsh/config/terminfo new file mode 100755 index 0000000..0202b50 --- /dev/null +++ b/zsh/config/terminfo @@ -0,0 +1,26 @@ +#!/bin/zsh +_DEPENDENCIES+=( + tic +) +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### + +SETUP_TERMINFO() { + [ ! $TERMINFO_PATH ] && return 0 + [ ! -d $TERMINFO_PATH ] && __FAIL 1 "TERMINFO_PATH='$TERMINFO_PATH' does not exist" + + local ERRORS=0 + for TERMINFO in $(find $TERMINFO_PATH -type f) + do + tic -x $TERMINFO >/dev/null 2>&1 \ + && __SUCCESS "added '$(basename $TERMINFO)'" \ + || __ERROR "failed to add '$(basename $TERMINFO)'" \ + ; + done + + __ERROR_CHECK +} + +##################################################################### +SETUP_TERMINFO $@ diff --git a/zsh/config/update b/zsh/config/update new file mode 100755 index 0000000..c0f971f --- /dev/null +++ b/zsh/config/update @@ -0,0 +1,10 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### + +__STATUS 'updating all config files and links' +__RUN_SCWRYPT zsh/config/symlinks || exit 1 +__RUN_SCWRYPT zsh/config/terminfo || exit 2 +__SUCCESS 'finished updating config files and links' diff --git a/zsh/git/common.zsh b/zsh/git/common.zsh new file mode 100644 index 0000000..75a9cfa --- /dev/null +++ b/zsh/git/common.zsh @@ -0,0 +1,6 @@ +_DEPENDENCIES+=( + git +) +_REQUIRED_ENV+=() +source ${0:a:h}/../common.zsh +##################################################################### diff --git a/zsh/git/package/build b/zsh/git/package/build new file mode 100755 index 0000000..15b64f2 --- /dev/null +++ b/zsh/git/package/build @@ -0,0 +1,6 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### +__RUN_SCWRYPT zsh/git/package/install -- --only-build $@ diff --git a/zsh/git/package/common.zsh b/zsh/git/package/common.zsh new file mode 100644 index 0000000..a0d688d --- /dev/null +++ b/zsh/git/package/common.zsh @@ -0,0 +1,73 @@ +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/../common.zsh +##################################################################### + +PACKAGE_INSTALL_DIR="$HOME/.local/share/source-packages" + +##################################################################### + +CLONE() { + cd "$PACKAGE_INSTALL_DIR" + __STATUS "downloading $NAME" + git clone "$TARGET" "$NAME" \ + && __SUCCESS "successfully downloaded '$NAME'" \ + || __FAIL 1 "failed to download '$NAME'" \ + ; +} + +PULL() { + __STATUS "updating '$NAME'" + cd "$PACKAGE_INSTALL_DIR/$NAME" + git pull origin $(git rev-parse --abbrev-ref HEAD) \ + && __SUCCESS "successfully updated '$NAME'" \ + || __FAIL 1 "failed to update '$NAME'" \ + ; +} + +##################################################################### + +BUILD() { + cd "$PACKAGE_INSTALL_DIR/$NAME" + + CHECK_MAKE && { MAKE && return 0 || return 1; } + CHECK_MAKEPKG && { MAKEPKG && return 0 || return 2; } + + __WARNING 'could not detect supported installation method' + + __REMINDER 'complete manual installation in the directory below:' + __REMINDER "$PACKAGE_INSTALL_DIR/$NAME" +} + +CHECK_MAKE() { [ -f ./Makefile ]; } +CHECK_MAKEPKG() { [ -f ./PKGBUILD ]; } + +MAKE() { + [[ $CLEAN -eq 1 ]] && { + __STATUS "cleaning '$NAME'" + make clean + } + + __STATUS "building '$NAME'" + make \ + && __SUCCESS "finished building '$NAME'" \ + || __FAIL 1 "build failed for '$NAME' (see above)"\ + ; + + __STATUS "installing '$NAME'" + __GETSUDO + sudo make install \ + && __SUCCESS "succesfully installed '$NAME'" \ + || __FAIL 2 "failed to install '$NAME' (see above)"\ + ; +} + +MAKEPKG() { + __STATUS "installing '$NAME'" + yes | makepkg -si \ + && __SUCCESS "succesfully installed '$NAME'" \ + || __FAIL 1 "failed to install '$NAME' (see above)"\ + ; +} + +##################################################################### diff --git a/zsh/git/package/download b/zsh/git/package/download new file mode 100755 index 0000000..5f9f293 --- /dev/null +++ b/zsh/git/package/download @@ -0,0 +1,6 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### +__RUN_SCWRYPT zsh/git/package/install -- --only-pull $@ diff --git a/zsh/git/package/install b/zsh/git/package/install new file mode 100755 index 0000000..23e7234 --- /dev/null +++ b/zsh/git/package/install @@ -0,0 +1,88 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### + +INSTALL() { + local USAGE=" + usage: [...options...] + + options + -t, --target-url target URL; required for first-time download + -n, --local-name local name for package (optional) + + -u, --update if package exists, update without prompt + -b, --only-build if package exists, skip update step and only build + -p, --only-pull skip the automated build step + -c, --clean for make, run make clean before build + + -h, --help print this message and exit + " + local NAME + local TARGET + + local SKIP_BUILD=0 + local SKIP_PULL=0 + local UPDATE=0 + local CLEAN=0 + + while [[ $# -gt 0 ]] + do + case $1 in + -t | --target-url ) TARGET="$2"; shift 1 ;; + -n | --local-name ) NAME="$2"; shift 1 ;; + + -u | --update ) UPDATE=1 ;; + -b | --only-build ) SKIP_PULL=1 ;; + -p | --only-pull ) SKIP_BUILD=1 ;; + -c | --clean ) CLEAN=1 ;; + + -h | --help ) __USAGE; exit 0 ;; + + -* ) __ERROR "unknown argument '$1'" ;; + + * ) [ ! $TARGET ] && TARGET="$1" \ + || __ERROR "extra positional argument '$1'" \ + ; + ;; + esac + shift 1 + done + + [[ $SKIP_PULL -eq 1 ]] && [[ $SKIP_BUILD -eq 1 ]] && __ERROR 'only one of [-b | -p] can be specified' + + [ ! $TARGET ] && [ ! $NAME ] && { + [[ $SKIP_BUILD -eq 1 ]] && { + __ERROR 'cannot skip build without specifying package local-name' + } || { + UPDATE=1 + NAME=$(ls "$PACKAGE_INSTALL_DIR" | __FZF 'select a package to update') + [ ! $NAME ] && __ERROR 'target-url required' + } + } + + __ERROR_CHECK + + #################################################### + + [ ! $NAME ] && { + NAME=$(echo $TARGET | sed 's/.*\///; s/\.git$//') + __INFO "using default name '$NAME'" + } + + [ -d "$PACKAGE_INSTALL_DIR/$NAME" ] && [[ $SKIP_PULL -eq 0 ]] && { + [[ $UPDATE -eq 0 ]] && __Yn "package '$NAME' already exists; update now?" && UPDATE=1 + [[ $UPDATE -eq 1 ]] && PULL || return 1 + } + + [ ! -d "$PACKAGE_INSTALL_DIR/$NAME" ] && { + CLONE || return 2 + } + + [[ $SKIP_BUILD -eq 1 ]] && return 0 + BUILD +} + +##################################################################### +INSTALL $@ diff --git a/zsh/git/package/update b/zsh/git/package/update new file mode 100755 index 0000000..d05939e --- /dev/null +++ b/zsh/git/package/update @@ -0,0 +1,6 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### +__RUN_SCWRYPT zsh/git/package/install -- --update $@ diff --git a/zsh/memo/open b/zsh/memo/open index c7ba1f6..4df0608 100755 --- a/zsh/memo/open +++ b/zsh/memo/open @@ -21,9 +21,7 @@ OPEN_MEMO() { DATESTRING="## $(date '+%A, %B %-d, %Y')" grep -q "$DATESTRING" "$MEMO_FILE" || echo "$DATESTRING" >> "$MEMO_FILE" - __STATUS "opening memo '$MEMO_NAME' for editing" __EDIT "$MEMO_FILE" - __SUCCESS "finished editing memo '$MEMO_NAME'" } diff --git a/zsh/scwrypts/configure b/zsh/scwrypts/configure index 392cb03..16d6760 100755 --- a/zsh/scwrypts/configure +++ b/zsh/scwrypts/configure @@ -29,9 +29,7 @@ source ${0:a:h}/common.zsh __REMINDER '(equivalent to "npm install" or "pip install -r requirements.txt")' __REMINDER } || { - __STATUS 'opening local config for editing' __EDIT $SCWRYPTS_CONFIG_PATH/config - __STATUS 'finished editing!' } diff --git a/zsh/scwrypts/environment/common.zsh b/zsh/scwrypts/environment/common.zsh index 8cf1c5e..683c83b 100644 --- a/zsh/scwrypts/environment/common.zsh +++ b/zsh/scwrypts/environment/common.zsh @@ -6,6 +6,7 @@ source ${0:a:h}/../common.zsh _SORT_ENV() { local ENV_FILE="$1" + sed -i "/^# /d; /^$/d" "$ENV_FILE" sed -i "s/^[A-Z]/export &/; s/^[^#=]\\+$/&=/" "$ENV_FILE" LC_COLLATE=C sort -uo "$ENV_FILE" "$ENV_FILE" } diff --git a/zsh/scwrypts/environment/edit b/zsh/scwrypts/environment/edit index b711710..09b6351 100755 --- a/zsh/scwrypts/environment/edit +++ b/zsh/scwrypts/environment/edit @@ -17,16 +17,14 @@ ENV_FILE=$(__GET_ENV_FILE $ENV_NAME) [ ! -f $ENV_FILE ] && { __STATUS "Creating '$ENV_NAME'..." \ && cp $__ENV_TEMPLATE $ENV_FILE \ - && __SUCCESS 'created!' \ + && __RUN_SCWRYPT zsh/scwrypts/environment/synchronize -- --no-prompt \ + && __SUCCESS "created '$ENV_NAME'" \ || { __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 +_SORT_ENV $ENV_FILE -__STATUS "finished editing; looking for new environment variables" while read line do ENV_VAR=$(echo "$line" | sed 's/=.*$//; s/^export //') diff --git a/zsh/scwrypts/environment/synchronize b/zsh/scwrypts/environment/synchronize index 3f36ae0..52c3e12 100755 --- a/zsh/scwrypts/environment/synchronize +++ b/zsh/scwrypts/environment/synchronize @@ -27,6 +27,7 @@ _SYNCHRONIZE() { _INSERT_NEW_VARIABLES _REMOVE_OLD_VARIABLES _SORT_AND_CASCADE + _ADD_DESCRIPTIONS __SUCCESS 'finished sync!' } @@ -126,5 +127,27 @@ _CASCADE_ENVIRONMENT() { __SUCCESS "finished '$PARENT_NAME' propagation" } +_ADD_DESCRIPTIONS() { + __STATUS 'updating descriptions' + while read DESCRIPTION_LINE + do + ENV_VAR=$(echo $DESCRIPTION_LINE | sed 's/ \+| .*$//') + DESCRIPTION=$(echo $DESCRIPTION_LINE | sed 's/^.* | //') + for ENV_NAME in $(echo $ENVIRONMENTS) + do + sed -i "/^export $ENV_VAR=/i # $DESCRIPTION" "$(__GET_ENV_FILE $ENV_NAME)" + done + done < <(sed -n '/^[^ ]\+ \+| /p' "$__ENV_TEMPLATE.descriptions") + + while read ENV_VAR + do + for ENV_NAME in $(echo $ENVIRONMENTS) + do + sed -i "/^export $ENV_VAR=/a \ " "$(__GET_ENV_FILE $ENV_NAME)" + sed -i "s/^ $//" "$(__GET_ENV_FILE $ENV_NAME)" + done + done < <(grep -B1 '^$' "$__ENV_TEMPLATE.descriptions" | grep '|' | awk '{print $1;}') +} + ##################################################################### _SYNCHRONIZE $@ diff --git a/zsh/utils/io.zsh b/zsh/utils/io.zsh index 9b1a24e..b351196 100644 --- a/zsh/utils/io.zsh +++ b/zsh/utils/io.zsh @@ -8,7 +8,7 @@ __PRINT() { printf "${COLOR}${MESSAGE}${__COLOR_RESET}${LINE_END}" } -__ERROR() { __PRINT $__RED "ERROR ✖ : $@" >&2; } +__ERROR() { __PRINT $__RED "ERROR ✖ : $@" >&2; ((ERRORS+=1)); } __SUCCESS() { __PRINT $__GREEN "SUCCESS ✔ : $@" >&2; } __WARNING() { __PRINT $__ORANGE "WARNING  : $@" >&2; } __STATUS() { __PRINT $__BLUE "STATUS : $@" >&2; } @@ -23,6 +23,28 @@ __PROMPT() { __FAIL() { __ERROR "${@:2}"; exit $1; } __ABORT() { __FAIL 69 'user abort'; } + +__ERROR_CHECK() { + [ ! $ERRORS ] && ERRORS=0 + [[ $ERRORS -ne 0 ]] && __USAGE + [[ $ERRORS -eq 0 ]] || exit $ERRORS +} + +__USAGE() { + [ ! $USAGE ] && return 0 + USAGE=$(echo $USAGE | sed "s/^\t\+//; s/\s\+$//") + + local USAGE_LINE=$(\ + echo $USAGE \ + | grep -i '^ *usage *:' \ + | sed "s;^[^:]*:;& scwrypts -- $SCWRYPT_NAME;" \ + | sed 's/ \{2,\}/ /g; s/scwrypts -- scwrypts/scwrypts/' \ + ) + local THE_REST=$(echo $USAGE | grep -vi '^ *usage *:' | sed 'N;/^\n$/D;P;D;') + + { echo; __PRINT $__DARK_BLUE "$USAGE_LINE"; echo $THE_REST; echo } >&2 +} + __INPUT() { __PROMPT "${@:2}" __READ $1 @@ -81,5 +103,8 @@ __EDIT() { __ERROR 'currently in CI, but __EDIT explicitly requires terminal input' return 1 } + + __STATUS "opening '$1' for editing" $EDITOR $@ /dev/tty + __SUCCESS "finished editing '$1'!" } diff --git a/zsh/utils/utils.module.zsh b/zsh/utils/utils.module.zsh index 80f94f5..54ddf15 100644 --- a/zsh/utils/utils.module.zsh +++ b/zsh/utils/utils.module.zsh @@ -14,12 +14,6 @@ source ${0:a:h}/credits.zsh IMPORT_ERROR=0 -[ $CI ] && { - export _AWS_PROFILE="$AWS_PROFILE" - export _AWS_ACCOUNT="$AWS_ACCOUNT" - export _AWS_REGION="$AWS_REGION" -} - source ${0:a:h}/dependencies.zsh _DEP_ERROR=0 _DEPENDENCIES=($(echo $_DEPENDENCIES | sort -u)) diff --git a/zsh/vim/common.zsh b/zsh/vim/common.zsh new file mode 100644 index 0000000..6634dc0 --- /dev/null +++ b/zsh/vim/common.zsh @@ -0,0 +1,8 @@ +_DEPENDENCIES+=( + vim +) +_REQUIRED_ENV+=() +source ${0:a:h}/../common.zsh +##################################################################### + +_VIM() { vim $@ /dev/tty; } diff --git a/zsh/vim/vundle/common.zsh b/zsh/vim/vundle/common.zsh new file mode 100644 index 0000000..0521595 --- /dev/null +++ b/zsh/vim/vundle/common.zsh @@ -0,0 +1,49 @@ +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/../common.zsh +##################################################################### + +VUNDLE_PLUGIN_DIR="$HOME/.vim/bundle" +VUNDLE_BUILD_DEFINITIONS="$VUNDLE_PLUGIN_DIR/build.zsh" + +[ ! -f $VUNDLE_BUILD_DEFINITIONS ] && { + { + echo -e "#\n# Scwrypts Build Definitions\n#\n" + } > $VUNDLE_BUILD_DEFINITIONS +} + +VUNDLE_PLUGIN_LIST=$(ls $VUNDLE_PLUGIN_DIR | grep -v 'Vundle.vim' | grep -v 'build.zsh') +source $VUNDLE_BUILD_DEFINITIONS +for PLUGIN in $(echo $VUNDLE_PLUGIN_LIST) +do + typeset -f VUNDLE_BUILD__$PLUGIN >/dev/null 2>/dev/null || { + echo -e "\nVUNDLE_BUILD__$PLUGIN() {\n # ... build steps from $HOME/.vim/$PLUGIN \n}" \ + >> $VUNDLE_BUILD_DEFINITIONS + VUNDLE_BUILD__$PLUGIN() {} + } +done + +##################################################################### + +VUNDLE_PLUGIN_INSTALL() { + _VIM +PluginInstall +qall \ + && __SUCCESS 'successfully installed Vundle.vim plugins' \ + || __FAIL 1 'failed to install Vundle.vim plugins' +} + +VUNDLE_REBUILD_PLUGINS() { + local ERRORS=0 + + local PLUGIN + for PLUGIN in $(echo $VUNDLE_PLUGIN_LIST) + do + cd "$VUNDLE_PLUGIN_DIR/$PLUGIN" + __STATUS "building '$PLUGIN'" + VUNDLE_BUILD__$PLUGIN \ + && __SUCCESS "finished building '$PLUGIN'" \ + || __ERROR "failed to build '$PLUGIN' (see above)" \ + ; + done + + return $ERRORS +} diff --git a/zsh/vim/vundle/edit-build-actions b/zsh/vim/vundle/edit-build-actions new file mode 100755 index 0000000..95a4d56 --- /dev/null +++ b/zsh/vim/vundle/edit-build-actions @@ -0,0 +1,6 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### +__EDIT "$VUNDLE_BUILD_DEFINITIONS" diff --git a/zsh/vim/vundle/install b/zsh/vim/vundle/install new file mode 100755 index 0000000..fbd1f01 --- /dev/null +++ b/zsh/vim/vundle/install @@ -0,0 +1,13 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### + +PLUGIN_INSTALL() { + VUNDLE_PLUGIN_INSTALL || return 1 + VUNDLE_REBUILD_PLUGINS || return 2 +} + +##################################################################### +PLUGIN_INSTALL $@ diff --git a/zsh/vim/vundle/rebuild b/zsh/vim/vundle/rebuild new file mode 100755 index 0000000..888eb38 --- /dev/null +++ b/zsh/vim/vundle/rebuild @@ -0,0 +1,6 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### +VUNDLE_REBUILD_PLUGINS $@