diff --git a/lang/go b/lang/go deleted file mode 100644 index d316495..0000000 --- a/lang/go +++ /dev/null @@ -1,5 +0,0 @@ -# GoLang -export GOROOT=/opt/go/bin -export PATH=$GOROOT/bin:$PATH -export GOPATH=/opt/go/workspace -export PATH=$GOPATH/bin:$PATH diff --git a/modules/editing/block/block.sh b/modules/editing/block/block.sh index 81ec2ba..752a76f 100755 --- a/modules/editing/block/block.sh +++ b/modules/editing/block/block.sh @@ -8,6 +8,7 @@ BLOCK_DESCRIPTION="" function __update_block () { if [ ! -z "$BLOCK_FILE" ]; then + mkdir -p "$(dirname $BLOCK_FILE)" touch $BLOCK_FILE tail -c1 $BLOCK_FILE | read -r _ || echo >> $BLOCK_FILE fi @@ -30,7 +31,7 @@ function set_block () { declare OPTIND while getopts ':f:c:d:n:' OPTION; do - echo $OPTION $OPTARG + # echo $OPTION $OPTARG case "$OPTION" in f) BLOCK_FILE=$OPTARG @@ -54,14 +55,14 @@ done shift $(( OPTIND - 1 )) __update_block - echo -e "new block template follows use: block-add >\n" $BLOCK - echo ---- + # echo -e "new block template follows use: block-add >\n" $BLOCK + # echo ---- echo $([ -e "$BLOCK_FILE" ] || echo "Warning: No output file set yet, use block-set -f " && echo "block will be placed in $BLOCK_FILE") - echo ------- + # echo ------- } - function add_block () { +block_remove_content # only add if it doesn't exist, existance is only based on block begin local ADD ADD=$(echo "${BLOCK}" | sed 's/\//\\\//g') @@ -71,6 +72,7 @@ sed -n '/^[ \t]*'"${BLOCK_BEGIN}"'/{q50}' "${BLOCK_FILE}" WHERE=${1-${BLOCK_BEGIN}} # default is end # echo Where $WHERE sed -i '/'"${WHERE}"'/{s/.*/&\n'"${ADD}"'/;h};${x;/^$/{s//'"$ADD"'/;H};x}' "${BLOCK_FILE}" +[[ $1 ]] && block_add_line $1 else echo "no file set in which to add block, use: ${RED_COLOR}set-block -f " fi @@ -112,7 +114,6 @@ remove_block () { }' "${BLOCK_FILE}" } - block_remove_content () { sed -i '/^'"${BLOCK_BEGIN}"'/,/^'"${BLOCK_END}"$'/ { /'"${BLOCK_BEGIN}"'/b @@ -121,7 +122,6 @@ block_remove_content () { }' "${BLOCK_FILE}" } - block_add_line () { # echo argument count $#, $1, $2, $3 local ADD diff --git a/modules/module.sh b/modules/module.sh deleted file mode 100644 index d5a3ebe..0000000 --- a/modules/module.sh +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/env bash -# shebang for syntax detection, not a command -# do *not* set executable! - -declare -Ag _modules_ - -shopt -s expand_aliases -alias _args_='(( $# ))' -alias _to_args_='set --' - -module.already_loaded () { - declare -Ag _modules_ - [[ -v _modules_[${BASH_SOURCE[1]}] ]] -} - -_blank_ () { - [[ -z ${1:-} ]] -} - -_defined_ () { - [[ -v $1 ]] -} - -_eq_ () { - [[ $1 == "${2:-}" ]] -} - -_functions_ () { - env -i bash </dev/null - compgen -A function;: -END -} - -_in_ () { - [[ $IFS$1$IFS == *"$IFS$2$IFS"* ]] -} - -_pop_ () { - local -n ref1=$1 - local ref2=${2:-} - - _present_ $ref2 && printf -v $ref2 %s "${ref1[-1]}" - unset -v $1[-1] -} - -_present_ () { - [[ -n ${1:-} ]] -} - -_push_ () { - local -n ref=$1 - - ref+=( "$2" ) -} - -_parent_=${BASH_SOURCE[1]:-} - -[[ ${1:-} != module ]] && return -set -- ${*:2} - -_numargs_+=( $# ) - -{ ! _args_ && _present_ ${_file_:-} && _eq_ $_parent_ $_file_ ;} && return - -{ ! _args_ && _present_ $_parent_ && ! _eq_ ${_parent_##*/} module ;} && { - _in_ "${_ancestors_[*]:-}" $_parent_ && return - _push_ _ancestors_ $_parent_ -} - -! _args_ && _to_args_ $_parent_ - -for _file_; do - _module_=${_file_%%=*} - _file_=${_file_#*=} - - _defined_ _modules_[$_file_] && continue - - _eq_ $_module_ $_file_ && { - _module_=${_module_##*/} - _module_=${_module_%.*} - } - - _prefixes_+=( $_module_ ) - - _push_ _aliases_ "$(alias)" - unalias -a - - _functions_=$(_functions_ $_file_) - - for _function_ in $_functions_; do - printf -v _prefix_ %s. ${_prefixes_[*]} - alias $_function_=$_prefix_$_function_ - done - - _push_ _files_ $_file_ - _push_ _funcs_ "$_functions_" - - set -- - source $_file_ - - unset -v _prefixes_[-1] - - _pop_ _files_ _file_ - _pop_ _funcs_ _functions_ - - _modules_[$_file_]='' - - for _function_ in $_functions_; do - unalias $_function_ - done - - eval "${_aliases_[-1]}" - _pop_ _aliases_ -done - -! (( ${#_files_[*]} )) && { - unalias _args_ - unalias _to_args_ - unset -f _blank_ - unset -f _defined_ - unset -f _eq_ - unset -f _in_ - unset -f _pop_ - unset -f _present_ - unset -f _push_ - unset -v _file_ - unset -v _funcs_ - unset -v _function_ - unset -v _functions_ - unset -v _module_ - unset -v _name_ - unset -v _parent_ - unset -v _prefix_ - unset -v _prefixes_ -} -{ ! (( _numargs_[-1] )) && [[ -n ${BASH_SOURCE[1]} && ${BASH_SOURCE[1]##*/} != module ]] ;} && unset -v _ancestors_[-1] -unset -v _numargs_[-1] - diff --git a/modules/modules.sh b/modules/modules.sh deleted file mode 100644 index e381eea..0000000 --- a/modules/modules.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -# must have fuser and bindfs installed -module-load () { -BASH_MODULES="${BASH_MODULES:-/opt/bash/modules}" -MODULES=$1 -echo $MODULES -for i in ${MODULES[@]}; do - echo $BASH_MODULES ${i} - . "$BASH_MODULES"/"$i".sh -done -} diff --git a/modules/utility/confirm.sh b/modules/utility/confirm.sh new file mode 100644 index 0000000..2653676 --- /dev/null +++ b/modules/utility/confirm.sh @@ -0,0 +1,47 @@ +# ====================================================================== +# +# @link http://wuhrr.wordpress.com/2010/01/13/adding-confirmation-to-bash/#comment-3540 +# +# Function: confirm +# Asks the user to confirm an action, If the user does not answer yes, +# then the script will immediately exit. +# +# Parameters: +# $@ - The confirmation message +# +# Examples: +# > # Example 1 +# > # The preferred way to use confirm +# > confirm Delete file1? && echo rm file1 +# > +# > # Example 2 +# > # Use the $? variable to examine confirm's return value +# > confirm Delete file2? +# > if [ $? -eq 0 ] +# > then +# > echo Another file deleted +# > fi +# > +# > # Example 3 +# > # Tell bash to exit right away if any command returns a non-zero code +# > set -o errexit +# > confirm Do you want to run the rest of the script? +# > echo Here is the rest of the script +# +# ====================================================================== + +function confirm() +{ + echo -n "$@ " + read -e answer + for response in y Y yes YES Yes Sure sure SURE OK ok Ok + do + if [ "_$answer" == "_$response" ] + then + return 0 + fi + done + + # Any answer other than the list above is considered a "no" answer + return 1 +} diff --git a/modules/utility/machine.sh b/modules/utility/machine.sh new file mode 100644 index 0000000..013829b --- /dev/null +++ b/modules/utility/machine.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +function get_platform () { + + local OS + local ARCH + local PLATFORM + + OS="$(uname -s)" + ARCH="$(uname -m)" + + case $OS in + "Linux") + case $ARCH in + "x86_64") + ARCH=amd64 + ;; + "aarch64") + ARCH=arm64 + ;; + "armv6") + ARCH=armv6l + ;; + "armv8") + ARCH=arm64 + ;; + .*386.*) + ARCH=386 + ;; + esac + PLATFORM="linux-$ARCH" + ;; + "Darwin") + PLATFORM="darwin-amd64" + ;; + esac + + echo $PLATFORM + +}