From b6a18688c49634d5d9e04c9834fb78afb31823dd Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Thu, 12 Jan 2023 16:49:49 +0200 Subject: [PATCH] Fix shfmt command and formatted files --- local/bin/dfm | 33 +++------ local/bin/x-ssl-expiry-date | 139 ++++++++++++++++++------------------ local/bin/x-until-error | 2 +- local/bin/x-until-success | 2 +- local/bin/x-when-down | 6 +- local/bin/x-when-up | 8 +-- scripts/install-dotfiles.sh | 1 - scripts/shared.sh | 55 +++++++++----- 8 files changed, 126 insertions(+), 120 deletions(-) diff --git a/local/bin/dfm b/local/bin/dfm index e6a3cf7..cf0abc2 100755 --- a/local/bin/dfm +++ b/local/bin/dfm @@ -48,13 +48,13 @@ function section_install ;; *) menu_section "$USAGE_PREFIX" "all | antigen | brew | macos | ext_go | ext_gh | settler" - menu_item "all" "Installs antigen, macos, brew, ext_gh and ext_go" - menu_item "antigen" "Updates the antigen.zsh file" - menu_item "brew" "Install Brewfile contents" - menu_item "ext_gh" "Install GitHub CLI Extensions" - menu_item "ext_go" "Install Go Packages" - menu_item "macos" "Setup nice macOS defaults" - menu_item "settler" "Runs the WIP settler.sh" + menu_item "all" "Installs antigen, macos, brew, ext_gh and ext_go" + menu_item "antigen" "Updates the antigen.zsh file" + menu_item "brew" "Install Brewfile contents" + menu_item "ext_gh" "Install GitHub CLI Extensions" + menu_item "ext_go" "Install Go Packages" + menu_item "macos" "Setup nice macOS defaults" + menu_item "settler" "Runs the WIP settler.sh" ;; esac } @@ -115,24 +115,13 @@ function section_dotfiles ;; shfmt) # Format shell scripts according to following rules. - shfmt \ - --find \ - --list \ - --write \ - --diff \ - --simplify \ - --indent 2 \ - --binary-next-line \ - --case-indent \ - --space-redirects \ - --func-next-line \ - "$DOTFILES" + shfmt -fn -l -w -i 2 -ci -sr -bn "$DOTFILES" ;; *) menu_section "$USAGE_PREFIX" "link | update | shfmt" - menu_item "link" "Use rcrc to update dotfile links" - menu_item "update" "Updates dotfile links, installs host specific overrides automatically" - menu_item "shfmt" "Run shfmt to all dotfiles" + menu_item "link" "Use rcrc to update dotfile links" + menu_item "update" "Updates dotfile links, installs host specific overrides automatically" + menu_item "shfmt" "Run shfmt to all dotfiles" ;; esac } diff --git a/local/bin/x-ssl-expiry-date b/local/bin/x-ssl-expiry-date index 16500f1..d8c1d70 100755 --- a/local/bin/x-ssl-expiry-date +++ b/local/bin/x-ssl-expiry-date @@ -20,9 +20,10 @@ # # Simple function to show usage information, and exit. # -usage() { - echo "Usage: $0 [-d] [-p 443] domain1.org domain2.com .. domainN" - exit 0 +usage() +{ + echo "Usage: $0 [-d] [-p 443] domain1.org domain2.com .. domainN" + exit 0 } # @@ -35,19 +36,19 @@ port=443 # Parse the argument(s) - i.e. look for "-d" / "-p 443". # while getopts "h?dp:" opt; do - case $opt in - h) - usage - ;; - \?) - usage - ;; - d) - days=1 - ;; - p) - port=$OPTARG - ;; + case $opt in + h) + usage + ;; + \?) + usage + ;; + d) + days=1 + ;; + p) + port=$OPTARG + ;; esac done shift $((OPTIND - 1)) @@ -56,7 +57,7 @@ shift $((OPTIND - 1)) # Ensure we have some arguments # if [ "$#" = "0" ]; then - usage + usage fi # @@ -64,70 +65,70 @@ fi # for name in "$@"; do - # - # Make a temporary file - # - # Test if we have BSD or GNU version of mktemp - if ( strings "$(which mktemp)" | grep -q GNU); then - # We have the GNU version - tmp=$(mktemp) + # + # Make a temporary file + # + # Test if we have BSD or GNU version of mktemp + if (strings "$(which mktemp)" | grep -q GNU); then + # We have the GNU version + tmp=$(mktemp) else - # We have the BSD version - tmp=$(mktemp -t tmp) + # We have the BSD version + tmp=$(mktemp -t tmp) fi - # - # Download the certificate - # - if ( ! echo "" | openssl s_client -connect $name:$port > $tmp 2> /dev/null); then - echo "Failed to get cert from https://$name:$port/" - exit 3 + # + # Download the certificate + # + if (! echo "" | openssl s_client -connect $name:$port > $tmp 2> /dev/null); then + echo "Failed to get cert from https://$name:$port/" + exit 3 fi - # - # Get the expiry date - # - date=$(openssl x509 -in "$tmp" -noout -enddate | awk -F= '{print $2}') + # + # Get the expiry date + # + date=$(openssl x509 -in "$tmp" -noout -enddate | awk -F= '{print $2}') - # - # Remove the temporary file - # - rm -f "$tmp" + # + # Remove the temporary file + # + rm -f "$tmp" - # - # Convert the expiry date + todays date to seconds-past epoch - # - # Check if we have the BSD or the GNU version of date - if (strings "$(which date)" | grep -q GNU); then - # We have GNU this is easy - then=$(date --date "$date" +%s) + # + # Convert the expiry date + todays date to seconds-past epoch + # + # Check if we have the BSD or the GNU version of date + if (strings "$(which date)" | grep -q GNU); then + # We have GNU this is easy + then=$(date --date "$date" +%s) else - # We have BSD now it is getting complicated - year=$(echo "$date" | awk '{print $4}') - month=$(echo "$date" | awk '{print $1}') - day=$(echo "$date" | awk '{print $2}') - hour=$(echo "$date" | awk '{print $3}' | awk -F: '{print $1}') - minute=$(echo "$date" | awk '{print $3}' | awk -F: '{print $2}') - second=$(echo "$date" | awk '{print $3}' | awk -F: '{print $3}') - then=$(date -v${year}y -v${month} -v${day}d -v${hour}H -v${minute}M -v${second}S -u +%s) + # We have BSD now it is getting complicated + year=$(echo "$date" | awk '{print $4}') + month=$(echo "$date" | awk '{print $1}') + day=$(echo "$date" | awk '{print $2}') + hour=$(echo "$date" | awk '{print $3}' | awk -F: '{print $1}') + minute=$(echo "$date" | awk '{print $3}' | awk -F: '{print $2}') + second=$(echo "$date" | awk '{print $3}' | awk -F: '{print $3}') + then=$(date -v${year}y -v${month} -v${day}d -v${hour}H -v${minute}M -v${second}S -u +%s) fi - now=$(date +%s) + now=$(date +%s) - # - # Day diff - # - diff=$(("$then" - "$now")) - diff=$($diff / 86400) + # + # Day diff + # + diff=$(("$then" - "$now")) + diff=$($diff / 86400) - # - # All done - # - if [ "$days" = "1" ]; then - echo "${name}: ${diff}" + # + # All done + # + if [ "$days" = "1" ]; then + echo "${name}: ${diff}" else - echo "$name" - echo " Expires: ${date}" - echo " Days: ${diff}" + echo "$name" + echo " Expires: ${date}" + echo " Days: ${diff}" fi done diff --git a/local/bin/x-until-error b/local/bin/x-until-error index 13eef6d..e987eba 100755 --- a/local/bin/x-until-error +++ b/local/bin/x-until-error @@ -11,5 +11,5 @@ # If the status code was zero then repeat. # while [ $? -eq 0 ]; do - "$@" + "$@" done diff --git a/local/bin/x-until-success b/local/bin/x-until-success index a882c0d..77d1136 100755 --- a/local/bin/x-until-success +++ b/local/bin/x-until-success @@ -26,5 +26,5 @@ # If the status code was not zero then repeat. # while [ $? -ne 0 ]; do - "$@" + "$@" done diff --git a/local/bin/x-when-down b/local/bin/x-when-down index 726c555..3c04c24 100755 --- a/local/bin/x-when-down +++ b/local/bin/x-when-down @@ -14,8 +14,8 @@ # Ensure we received the correct number of arguments. # if [ $# -lt 2 ]; then - echo "Usage: $0 HOST COMMAND..." - exit 1 + echo "Usage: $0 HOST COMMAND..." + exit 1 fi HOST=$1 @@ -24,7 +24,7 @@ echo "Waiting for $HOST to get down..." true while [ $? -ne 1 ]; do - ping -c 1 -W 1 $HOST > /dev/null + ping -c 1 -W 1 $HOST > /dev/null done shift diff --git a/local/bin/x-when-up b/local/bin/x-when-up index 3fb6bde..b846626 100755 --- a/local/bin/x-when-up +++ b/local/bin/x-when-up @@ -18,8 +18,8 @@ # Ensure we received the correct number of arguments. # if [ $# -lt 2 ]; then - echo "Usage: $0 HOST COMMAND..." - exit 1 + echo "Usage: $0 HOST COMMAND..." + exit 1 fi if [ $1 = "ssh" ]; then @@ -32,8 +32,8 @@ echo "Waiting for $HOST to come online..." ping -c 1 -W 1 $HOST > /dev/null while [ $? -ne 0 ]; do - sleep 1 - ping -c 1 -W 1 $HOST > /dev/null + sleep 1 + ping -c 1 -W 1 $HOST > /dev/null done # By the time we reach here the ping-command has completed successfully diff --git a/scripts/install-dotfiles.sh b/scripts/install-dotfiles.sh index 1ac0662..38c7cbf 100644 --- a/scripts/install-dotfiles.sh +++ b/scripts/install-dotfiles.sh @@ -75,7 +75,6 @@ handle_file_ln "$HOME/.dotfiles/config/functions" "$HOME/.config/functions" handle_file_ln "$HOME/.dotfiles/config/gh/config.yml" "$HOME/.config/gh/config.yml" handle_file_ln "$HOME/.dotfiles/config/git/config" "$HOME/.config/git/config" handle_file_ln "$HOME/.dotfiles/config/git/gitignore" "$HOME/.config/git/gitignore" -handle_file_ln "$HOME/.dotfiles/config/nvim/after/plugin/defaults.lua" "$HOME/.config/nvim/after/plugin/defaults.lua" handle_file_ln "$HOME/.dotfiles/config/nvim/init.lua" "$HOME/.config/nvim/init.lua" handle_file_ln "$HOME/.dotfiles/config/nvim/lua/custom/plugins.lua" "$HOME/.config/nvim/lua/custom/plugins.lua" handle_file_ln "$HOME/.dotfiles/config/nvim/plugin/packer_compiled.lua" "$HOME/.config/nvim/plugin/packer_compiled.lua" diff --git a/scripts/shared.sh b/scripts/shared.sh index 3cabf26..a0e1aaf 100644 --- a/scripts/shared.sh +++ b/scripts/shared.sh @@ -12,78 +12,95 @@ CLR_BLUE='\033[1;34m' CLR_RESET="\033[0m" # -- Helpers -- # -function __log_marker() { +function __log_marker() +{ echo -e "${CLR_BLUE}➜${CLR_RESET}" } -function __log_marker_ok() { +function __log_marker_ok() +{ echo -e "${CLR_GREEN}✔${CLR_RESET}" } -function __log_marker_ok_blue() { +function __log_marker_ok_blue() +{ echo -e "${CLR_BLUE}✔${CLR_RESET}" } -function __log_marker_warn() { +function __log_marker_warn() +{ echo -e "${CLR_YELLOW}⁕${CLR_RESET}" } -function __log_marker_err() { +function __log_marker_err() +{ echo -e "${CLR_RED}⛌${CLR_RESET}" } -function __log_indent() { +function __log_indent() +{ echo " " } # -- Log -- # -function msg() { +function msg() +{ echo -e "$(__log_marker) $1" } -function msg_done() { +function msg_done() +{ echo -e "$(__log_marker) $1 ...$(__log_marker_ok)" } -function msg_prompt() { +function msg_prompt() +{ echo -e "$(__log_marker) $1" } -function msg_prompt_done() { +function msg_prompt_done() +{ echo -e "$(__log_marker) $1 ...$(__log_marker_ok)" } -function msg_nested() { +function msg_nested() +{ echo -e "$(__log_indent)$(__log_marker) $1" } -function msg_nested_done() { +function msg_nested_done() +{ echo -e "$(__log_indent)$(__log_marker) $1 ...$(__log_marker_ok)" } -function msg_run() { +function msg_run() +{ echo -e "${CLR_GREEN}➜ $1${CLR_RESET} $2" } -function msg_ok() { +function msg_ok() +{ echo -e "$(__log_marker_ok) $1" } -function msg_warn() { +function msg_warn() +{ echo -e "$(__log_marker_warn) $1" } -function msg_err() { +function msg_err() +{ echo -e "$(__log_marker_err) $1" } # -- Menu builder -- # -function menu_section() { +function menu_section() +{ LINE=$(printf '%-18s [ %-15s ]\n' "$1" "$2") echo -e " $(__log_marker) $LINE" } -function menu_item() { +function menu_item() +{ LINE=$(printf '%-15s %-30s\n' "$1" "$2") echo -e "$(__log_indent)$(__log_marker) $LINE" } -