From 0e47db40155393bc7a696bf898389e2528364bf2 Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Fri, 30 Sep 2022 21:36:24 -0700 Subject: [PATCH] Run shfmt on all shell files --- bash/bin/cptemplate.sh | 118 ++++++++++++++++---------------- bash/bin/fedit.sh | 148 ++++++++++++++++++++--------------------- bash/fzf.sh | 2 +- bash/search.sh | 14 ++-- bash/version.sh | 2 +- 5 files changed, 142 insertions(+), 142 deletions(-) diff --git a/bash/bin/cptemplate.sh b/bash/bin/cptemplate.sh index 88458e4..a5396a5 100755 --- a/bash/bin/cptemplate.sh +++ b/bash/bin/cptemplate.sh @@ -8,14 +8,14 @@ trap 'exit 1' SIGINT LIBDIR="/usr/share/file-scripts/" for f in "$LIBDIR"/*.sh; do - source "${f}" + source "${f}" done DEFAULT_TEMPLATE_DIR="$HOME/Templates" # Helper functions function help() { -cat << HELPMESSAGE + cat <&2 - exit 1 - ;; - *) - break - ;; - esac + case "${1}" in + '-d' | '--dir') + DIR="${2}" + case "${DIR}" in + "") + exit 1 + ;; + -*) + exit 1 + ;; + esac + shift 2 + continue + ;; + --dir=*) + DIR="${1#*=}" + case "${DIR}" in + "") + exit 1 + ;; + -*) + exit 1 + ;; + esac + shift + continue + ;; + '-f' | '--force') + FORCE_OVERWRITE='--force' + shift + continue + ;; + '-h' | '--help') + help + exit + ;; + --) + shift + break + ;; + -*) + printf '%s\n' "Unknown option: ${1}" >&2 + exit 1 + ;; + *) + break + ;; + esac done # If directory wasn't overridden if [[ -z "$DIR" ]]; then - DIR="$DEFAULT_TEMPLATE_DIR" + DIR="$DEFAULT_TEMPLATE_DIR" fi # If no target specified if [[ -z "$1" ]]; then - printf '%s\n' 'Please specify target name' - exit 1 + printf '%s\n' 'Please specify target name' + exit 1 fi # Check if default template directory exists if ! [[ -d "$DIR" ]]; then - printf '%s\n' "Template directory doesn't exist, exiting." - exit 2 + printf '%s\n' "Template directory doesn't exist, exiting." + exit 2 fi files="$(find_files "$DIR")" @@ -104,10 +104,10 @@ selected_file="$(run_fzf "$files")" # Check if target exists if [[ -f "$1" && -z "$FORCE_OVERWRITE" ]]; then - printf '%s\n' 'File already exists, exiting' - exit 1 + printf '%s\n' 'File already exists, exiting' + exit 1 elif [[ -f "$1" && -n "$FORCE_OVERWRITE" ]]; then - cp --verbose --force -- "$selected_file" "$1" + cp --verbose --force -- "$selected_file" "$1" else - cp --verbose -- "$selected_file" "$1" + cp --verbose -- "$selected_file" "$1" fi diff --git a/bash/bin/fedit.sh b/bash/bin/fedit.sh index 460af56..c0c4050 100755 --- a/bash/bin/fedit.sh +++ b/bash/bin/fedit.sh @@ -8,7 +8,7 @@ trap 'exit 1' SIGINT LIBDIR="/usr/share/file-scripts/" for f in "$LIBDIR"/*.sh; do - source "${f}" + source "${f}" done BOOT_DIR='/boot' @@ -16,7 +16,7 @@ ETC_DIR='/etc' # Helper functions function help() { -cat << HELPMESSAGE + cat <&2 - exit 1 - ;; - *) - break - ;; - esac + case "${1}" in + '-b' | '--boot') + EDIT_BOOT=1 + shift + continue + ;; + '-d' | '--dir') + DIR="${2}" + case "${DIR}" in + "") + exit 1 + ;; + -*) + exit 1 + ;; + esac + shift 2 + continue + ;; + --dir=*) + DIR="${1#*=}" + case "${DIR}" in + "") + exit 1 + ;; + -*) + exit 1 + ;; + esac + shift + continue + ;; + '-E' | '--etc') + EDIT_ETC=1 + shift + continue + ;; + '-i' | '--no-ignore-vcs') + NO_IGNORE_VCS=1 + shift + continue + ;; + '-I' | '--no-ignore') + NO_IGNORE=1 + shift + continue + ;; + '-h' | '--help') + help + exit + ;; + --) + shift + break + ;; + -*) + printf '%s\n' "Unknown option: ${1}" >&2 + exit 1 + ;; + *) + break + ;; + esac done # Handle -b and -E, they are mutually exclusive if [[ -n $EDIT_BOOT && -z $EDIT_ETC ]]; then - DIR="$BOOT_DIR" + DIR="$BOOT_DIR" elif [[ -z $EDIT_BOOT && -n $EDIT_ETC ]]; then - DIR="$ETC_DIR" + DIR="$ETC_DIR" elif [[ -n $EDIT_BOOT && -n $EDIT_ETC ]]; then - printf '%s\n' 'Select either --boot or --etc, not both' - exit 1 + printf '%s\n' 'Select either --boot or --etc, not both' + exit 1 elif [[ -z $DIR ]]; then - DIR='.' + DIR='.' fi # Handle extra options declare -a extra_opts if [[ -n $NO_IGNORE ]]; then - extra_opts+=('--no-ignore') + extra_opts+=('--no-ignore') elif [[ -n $NO_IGNORE_VCS ]]; then - extra_opts+=('--no-ignore-vcs') + extra_opts+=('--no-ignore-vcs') fi files="$(find_files $DIR "${extra_opts[@]}")" selected_file="$(run_fzf "$files")" if [[ -w "${selected_file}" ]]; then - "$EDITOR" "$selected_file" + "$EDITOR" "$selected_file" else - sudo --edit "$selected_file" + sudo --edit "$selected_file" fi diff --git a/bash/fzf.sh b/bash/fzf.sh index e7df94e..bd311d8 100644 --- a/bash/fzf.sh +++ b/bash/fzf.sh @@ -3,5 +3,5 @@ FZF_OPTS=('--select-1' '--exit-0') run_fzf() { - fzf "${FZF_OPTS[@]}" -- <<< "$@" || return 2 + fzf "${FZF_OPTS[@]}" -- <<<"$@" || return 2 } diff --git a/bash/search.sh b/bash/search.sh index 93d5379..cc6f33f 100644 --- a/bash/search.sh +++ b/bash/search.sh @@ -6,11 +6,11 @@ DEFAULT_FD_OPTS=('--hidden' '--type' 'f' '--type' 'l' '--threads' "$(nproc)") # $1: directory # $2-n: extra arguments find_files() { - if [[ -d "$1" ]]; then - local directory="$1" - shift - fd "${DEFAULT_FD_OPTS[@]}" "$@" -- . "$directory" - else - fd "${DEFAULT_FD_OPTS[@]}" "$@" - fi + if [[ -d "$1" ]]; then + local directory="$1" + shift + fd "${DEFAULT_FD_OPTS[@]}" "$@" -- . "$directory" + else + fd "${DEFAULT_FD_OPTS[@]}" "$@" + fi } diff --git a/bash/version.sh b/bash/version.sh index ab5af11..9afc8aa 100644 --- a/bash/version.sh +++ b/bash/version.sh @@ -5,5 +5,5 @@ MINOR_VERSION=1 PATCH_VERSION=4 if [[ "$1" == '--print' ]]; then - echo "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}" + echo "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}" fi