From 3257b689d5406af9ac694b6068aef13dc74663c8 Mon Sep 17 00:00:00 2001 From: Nathaniel Landau Date: Wed, 6 Apr 2016 15:02:14 -0400 Subject: [PATCH] Reformatting --- lib/setupScriptFunctions.sh | 9 +++-- lib/sharedFunctions.sh | 75 ++++++++++++++++++++++++++----------- lib/utils.sh | 30 ++++----------- 3 files changed, 67 insertions(+), 47 deletions(-) diff --git a/lib/setupScriptFunctions.sh b/lib/setupScriptFunctions.sh index 422c445..753af1f 100755 --- a/lib/setupScriptFunctions.sh +++ b/lib/setupScriptFunctions.sh @@ -42,6 +42,7 @@ hasHomebrew () { ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew tap homebrew/dupes brew tap homebrew/versions + brew tap argon/mas else die "Without Homebrew installed we won't get very far." fi @@ -130,7 +131,7 @@ function doInstall () { if [[ "${list}" ]]; then seek_confirmation "Confirm each package before installing?" if is_confirmed; then - for item in ${list[@]} + for item in "${list[@]}" do seek_confirmation "Install ${item}?" if is_confirmed; then @@ -142,12 +143,12 @@ function doInstall () { brew tap tldr-pages/tldr brew install tldr else - ${INSTALLCOMMAND} ${item} + ${INSTALLCOMMAND} "${item}" fi fi done else - for item in ${list[@]} + for item in "${list[@]}" do notice "Installing ${item}" # FFMPEG takes additional flags @@ -157,7 +158,7 @@ function doInstall () { brew tap tldr-pages/tldr brew install tldr else - ${INSTALLCOMMAND} ${item} + ${INSTALLCOMMAND} "${item}" fi done fi diff --git a/lib/sharedFunctions.sh b/lib/sharedFunctions.sh index 59cfcd2..5c4f693 100755 --- a/lib/sharedFunctions.sh +++ b/lib/sharedFunctions.sh @@ -82,16 +82,17 @@ function convertsecs() { printf "%02d:%02d:%02d\n" $h $m $s } -# pushover -# ------------------------------------------------------ -# Sends notifications view Pushover -# Requires a file named 'pushover.cfg' be placed in '../etc/' -# -# Usage: pushover "Title Goes Here" "Message Goes Here" -# -# Credit: http://ryonsherman.blogspot.com/2012/10/shell-script-to-send-pushover.html -# ------------------------------------------------------ function pushover() { + # pushover + # ------------------------------------------------------ + # Sends notifications view Pushover + # Requires a file named 'pushover.cfg' be placed in '../etc/' + # + # Usage: pushover "Title Goes Here" "Message Goes Here" + # + # Credit: http://ryonsherman.blogspot.com/2012/10/shell-script-to-send-pushover.html + # ------------------------------------------------------ + # Check for config file containing API Keys if [ ! -f "${SOURCEPATH}/../etc/pushover.cfg" ]; then error "Please locate the pushover.cfg to send notifications to Pushover." @@ -469,20 +470,20 @@ squeeze_lines() { sed '/^[[:space:]]\+$/s/.*//g' | cat -s | trim_lines } -# progressBar -# ----------------------------------- -# Prints a progress bar within a for/while loop. -# To use this function you must pass the total number of -# times the loop will run to the function. -# -# usage: -# for number in $(seq 0 100); do -# sleep 1 -# progressBar 100 -# done -# ----------------------------------- progressBar() { + # progressBar + # ----------------------------------- + # Prints a progress bar within a for/while loop. + # To use this function you must pass the total number of + # times the loop will run to the function. + # + # usage: + # for number in $(seq 0 100); do + # sleep 1 + # progressBar 100 + # done + # ----------------------------------- if [[ "${quiet}" = "true" ]] || [ "${quiet}" == "1" ]; then return fi @@ -565,6 +566,38 @@ urldecode() { printf '%b' "${url_encoded//%/\x}" } +parse_yaml() { + # Function to parse YAML files and add values to variables. Send it to a temp file and source it + # https://gist.github.com/epiloque/8cf512c6d64641bde388 + # + # Usage: + # $ parse_yaml sample.yml > /some/tempfile + # + # parse_yaml accepts a prefix argument so that imported settings all have a common prefix + # (which will reduce the risk of namespace collisions). + # + # $ parse_yaml sample.yml "CONF_" + + local prefix=$2 + local s + local w + local fs + s='[[:space:]]*' + w='[a-zA-Z0-9_]*' + fs="$(echo @|tr @ '\034')" + sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \ + -e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" | + awk -F"$fs" '{ + indent = length($1)/2; + vname[indent] = $2; + for (i in vname) {if (i > indent) {delete vname[i]}} + if (length($3) > 0) { + vn=""; for (i=0; i