Format with vs-shell-format

This commit is contained in:
Éfrit 2020-03-31 23:51:00 +02:00
parent 30f5508bc3
commit 73aafa56e1
16 changed files with 306 additions and 255 deletions

1
.gitignore vendored
View File

@ -10,4 +10,3 @@
/.circleci/.config.yml /.circleci/.config.yml
.download .download
bin bin

1
.gitmodules vendored
View File

@ -1,4 +1,3 @@
[submodule "best"] [submodule "best"]
path = .test-framework path = .test-framework
url = https://github.com/eth-p/best.git url = https://github.com/eth-p/best.git

View File

@ -235,15 +235,35 @@ while shiftopt; do
case "$OPT" in case "$OPT" in
--install) OPT_INSTALL=true ;; --install) OPT_INSTALL=true ;;
--compress) OPT_COMPRESS=true ;; --compress) OPT_COMPRESS=true ;;
--prefix) shiftval; OPT_PREFIX="$OPT_VAL";; --prefix)
--alternate-executable) shiftval; OPT_BAT="$OPT_VAL";; shiftval
--minify) shiftval; OPT_MINIFY="$OPT_VAL";; OPT_PREFIX="$OPT_VAL"
--no-verify) shiftval; OPT_VERIFY=false;; ;;
--docs:url) shiftval; DOCS_URL="$OPT_VAL";; --alternate-executable)
--docs:maintainer) shiftval; DOCS_MAINTAINER="$OPT_VAL";; shiftval
OPT_BAT="$OPT_VAL"
;;
--minify)
shiftval
OPT_MINIFY="$OPT_VAL"
;;
--no-verify)
shiftval
OPT_VERIFY=false
;;
--docs:url)
shiftval
DOCS_URL="$OPT_VAL"
;;
--docs:maintainer)
shiftval
DOCS_MAINTAINER="$OPT_VAL"
;;
*) printc "%{RED}%s: unknown option '%s'%{CLEAR}" "$PROGRAM" "$OPT"; *)
exit 1;; printc "%{RED}%s: unknown option '%s'%{CLEAR}" "$PROGRAM" "$OPT"
exit 1
;;
esac esac
done done
@ -290,17 +310,17 @@ printc "%{YELLOW}Building scripts...%{CLEAR}\n" 1>&2
file_i=0 file_i=0
file_n="${#SOURCES[@]}" file_n="${#SOURCES[@]}"
for file in "${SOURCES[@]}"; do for file in "${SOURCES[@]}"; do
((file_i++)) || true; ((file_i++)) || true
filename="$(basename "$file" .sh)" filename="$(basename "$file" .sh)"
printc " %{YELLOW}[%s/%s] %{MAGENTA}%s%{CLEAR}\n" "$file_i" "$file_n" "$file" 1>&2 printc " %{YELLOW}[%s/%s] %{MAGENTA}%s%{CLEAR}\n" "$file_i" "$file_n" "$file" 1>&2
step_read "$file" |\ step_read "$file" |
next step_preprocess |\ next step_preprocess |
next step_minify |\ next step_minify |
next step_compress |\ next step_compress |
next step_write "${BIN}/${filename}" |\ next step_write "${BIN}/${filename}" |
next step_write_install "${OPT_PREFIX}/bin/${filename}" |\ next step_write_install "${OPT_PREFIX}/bin/${filename}" |
cat >/dev/null cat >/dev/null
done done
@ -312,4 +332,3 @@ if "$OPT_VERIFY"; then
"${HERE}/test.sh" --compiled "${HERE}/test.sh" --compiled
exit $? exit $?
fi fi

View File

@ -53,7 +53,6 @@ shiftopt() {
fi fi
done done
# Return.
return 0 return 0
} }
@ -81,7 +80,5 @@ shiftval() {
fi fi
} }
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
setargs "$@" setargs "$@"

View File

@ -6,13 +6,12 @@
# Issues: https://github.com/eth-p/bat-extras/issues # Issues: https://github.com/eth-p/bat-extras/issues
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Hooks: # Hooks:
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Option parser hook: color support. # Option parser hook: color support.
# This will accept --no-color, or --color. # This will accept --no-color or --color.
# It will also try to accept --color=never|always|auto. # It will also try to accept --color=never|always|auto.
# #
# The variable OPT_COLOR will be set depending on whether or not a TTY is # The variable OPT_COLOR will be set depending on whether or not a TTY is
@ -21,12 +20,21 @@ hook_color() {
SHIFTOPT_HOOKS+=("__shiftopt_hook__color") SHIFTOPT_HOOKS+=("__shiftopt_hook__color")
__shiftopt_hook__color() { __shiftopt_hook__color() {
case "$OPT" in case "$OPT" in
--no-color) OPT_COLOR=false; printc_init "$OPT_COLOR";; --no-color)
OPT_COLOR=false
printc_init "$OPT_COLOR"
;;
--color) { --color) {
case "$OPT_VAL" in case "$OPT_VAL" in
auto) : ;; auto) : ;;
always|true) OPT_COLOR=true; printc_init "$OPT_COLOR";; always | true)
never|false) OPT_COLOR=false; printc_init "$OPT_COLOR";; OPT_COLOR=true
printc_init "$OPT_COLOR"
;;
never | false)
OPT_COLOR=false
printc_init "$OPT_COLOR"
;;
esac esac
} ;; } ;;
@ -52,19 +60,25 @@ hook_pager() {
__shiftopt_hook__pager() { __shiftopt_hook__pager() {
case "$OPT" in case "$OPT" in
# Specify paging. # Specify paging.
--no-pager) shiftval; SCRIPT_PAGER_CMD='';; --no-pager)
--paging) shiftval; { shiftval
SCRIPT_PAGER_CMD=''
;;
--paging)
shiftval
{
case "$OPT_VAL" in case "$OPT_VAL" in
auto) : ;; auto) : ;;
never) SCRIPT_PAGER_CMD='' ;; never) SCRIPT_PAGER_CMD='' ;;
always) : ;; always) : ;;
esac esac
};; }
;;
# Specify the pager. # Specify the pager.
--pager) { --pager) {
shiftval; shiftval
SCRIPT_PAGER_CMD=($OPT_VAL); SCRIPT_PAGER_CMD=($OPT_VAL)
PAGER_ARGS=() PAGER_ARGS=()
} ;; } ;;
@ -72,4 +86,3 @@ hook_pager() {
esac esac
} }
} }

View File

@ -6,13 +6,13 @@
# Issues: https://github.com/eth-p/bat-extras/issues # Issues: https://github.com/eth-p/bat-extras/issues
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Returns 0 (true) if the current pager is less, otherwise 1 (false) # Returns 0 (true) if the current pager is less, otherwise 1 (false).
is_pager_less() { is_pager_less() {
[[ "$(pager_name)" = "less" ]] [[ "$(pager_name)" = "less" ]]
return $? return $?
} }
# Returns 0 (true) if the current pager is disabled, otherwise 1 (false) # Returns 0 (true) if the current pager is disabled, otherwise 1 (false).
is_pager_disabled() { is_pager_disabled() {
[[ -z "$(pager_name)" ]] [[ -z "$(pager_name)" ]]
return $? return $?
@ -34,7 +34,7 @@ pager_name() {
echo "$_SCRIPT_PAGER_NAME" echo "$_SCRIPT_PAGER_NAME"
} }
# Executes a command or function, and pipes its output to the pager (if exists). # Executes a command or function, and pipes its output to the pager (if it exists).
# #
# Returns: The exit code of the command. # Returns: The exit code of the command.
# Example: # Example:
@ -51,7 +51,7 @@ pager_exec() {
fi fi
} }
# Displays the output of a command or function inside the pager (if exists). # Displays the output of a command or function inside the pager (if it exists).
# #
# Example: # Example:
# bat | pager_display # bat | pager_display
@ -85,4 +85,3 @@ if ! [[ -t 1 ]]; then
SCRIPT_PAGER_CMD=() SCRIPT_PAGER_CMD=()
SCRIPT_PAGER_ARGS=() SCRIPT_PAGER_ARGS=()
fi fi

View File

@ -52,7 +52,7 @@ printc_init() {
esac esac
} }
# Print a warning message to STDERR. # Print a warning message to stderr.
# Arguments: # Arguments:
# 1 -- The printc formatting string. # 1 -- The printc formatting string.
# ... -- The printc formatting arguments. # ... -- The printc formatting arguments.
@ -60,7 +60,7 @@ print_warning() {
printc "%{YELLOW}[%s warning]%{CLEAR}: $1%{CLEAR}\n" "$PROGRAM" "${@:2}" 1>&2 printc "%{YELLOW}[%s warning]%{CLEAR}: $1%{CLEAR}\n" "$PROGRAM" "${@:2}" 1>&2
} }
# Print an error message to STDERR. # Print an error message to stderr.
# Arguments: # Arguments:
# 1 -- The printc formatting string. # 1 -- The printc formatting string.
# ... -- The printc formatting arguments. # ... -- The printc formatting arguments.
@ -82,4 +82,3 @@ printc_init <<END
DIM \x1B[2m DIM \x1B[2m
END END

View File

@ -15,4 +15,3 @@ tolower() {
toupper() { toupper() {
tr "[[:lower:]]" "[[:upper:]]" <<<"$1" tr "[[:lower:]]" "[[:upper:]]" <<<"$1"
} }

View File

@ -49,7 +49,7 @@ version_compare__recurse() {
# Compare the versions specially if the final number has been reached. # Compare the versions specially if the final number has been reached.
if [[ -z "$v_minor" && -z "$c_minor" ]]; then if [[ -z "$v_minor" && -z "$c_minor" ]]; then
[ "$v_major" $operator "$c_major" ]; [ "$v_major" $operator "$c_major" ];
return $?; return $?
fi fi
# Insert zeroes where there are missing numbers. # Insert zeroes where there are missing numbers.
@ -66,13 +66,15 @@ version_compare__recurse() {
case "$operator" in case "$operator" in
-eq) [[ "$v_major" -ne "$c_major" ]] && return 1 ;; -eq) [[ "$v_major" -ne "$c_major" ]] && return 1 ;;
-ne) [[ "$v_major" -ne "$c_major" ]] && return 0 ;; -ne) [[ "$v_major" -ne "$c_major" ]] && return 0 ;;
-ge|-gt) [[ "$v_major" -lt "$c_major" ]] && return 1; -ge | -gt)
[[ "$v_major" -gt "$c_major" ]] && return 0;; [[ "$v_major" -lt "$c_major" ]] && return 1
-le|-lt) [[ "$v_major" -gt "$c_major" ]] && return 1; [[ "$v_major" -gt "$c_major" ]] && return 0
[[ "$v_major" -lt "$c_major" ]] && return 0;; ;;
-le | -lt)
[[ "$v_major" -gt "$c_major" ]] && return 1
[[ "$v_major" -lt "$c_major" ]] && return 0
;;
esac esac
version_compare__recurse "$v_minor" "$operator" "$c_minor" version_compare__recurse "$v_minor" "$operator" "$c_minor"
} }

View File

@ -43,16 +43,28 @@ fi
while shiftopt; do while shiftopt; do
case "$OPT" in case "$OPT" in
# Ripgrep Options # ripgrep options
-i | --ignore-case) OPT_CASE_SENSITIVITY="--ignore-case" ;; -i | --ignore-case) OPT_CASE_SENSITIVITY="--ignore-case" ;;
-s | --case-sensitive) OPT_CASE_SENSITIVITY="--case-sensitive" ;; -s | --case-sensitive) OPT_CASE_SENSITIVITY="--case-sensitive" ;;
-S | --smart-case) OPT_CASE_SENSITIVITY="--smart-case" ;; -S | --smart-case) OPT_CASE_SENSITIVITY="--smart-case" ;;
-A|--after-context) shiftval; OPT_CONTEXT_AFTER="$OPT_VAL";; -A | --after-context)
-B|--before-context) shiftval; OPT_CONTEXT_BEFORE="$OPT_VAL";; shiftval
-C|--context) shiftval; OPT_CONTEXT_BEFORE="$OPT_VAL"; OPT_CONTEXT_AFTER="$OPT_VAL"
OPT_CONTEXT_AFTER="$OPT_VAL";; ;;
-B | --before-context)
shiftval
OPT_CONTEXT_BEFORE="$OPT_VAL"
;;
-C | --context)
shiftval
OPT_CONTEXT_BEFORE="$OPT_VAL"
OPT_CONTEXT_AFTER="$OPT_VAL"
;;
-F|--fixed-strings) OPT_FIXED_STRINGS=true; RG_ARGS+=("$OPT");; -F | --fixed-strings)
OPT_FIXED_STRINGS=true
RG_ARGS+=("$OPT")
;;
-U | --multiline | \ -U | --multiline | \
-P | --pcre2 | \ -P | --pcre2 | \
@ -71,18 +83,21 @@ while shiftopt; do
-m | --max-count | \ -m | --max-count | \
--max-depth | \ --max-depth | \
--iglob | \ --iglob | \
--ignore-file) shiftval; RG_ARGS+=("$OPT" "$OPT_VAL");; --ignore-file)
shiftval
RG_ARGS+=("$OPT" "$OPT_VAL")
;;
# Bat Options # bat options
# Script Options # Script options
--no-follow) OPT_FOLLOW=false ;; --no-follow) OPT_FOLLOW=false ;;
--no-snip) OPT_SNIP="" ;; --no-snip) OPT_SNIP="" ;;
--no-highlight) OPT_HIGHLIGHT=false ;; --no-highlight) OPT_HIGHLIGHT=false ;;
-p | --search-pattern) OPT_SEARCH_PATTERN=true ;; -p | --search-pattern) OPT_SEARCH_PATTERN=true ;;
--no-search-pattern) OPT_SEARCH_PATTERN=false ;; --no-search-pattern) OPT_SEARCH_PATTERN=false ;;
# Option Forwarding # Option forwarding
--rg:*) { --rg:*) {
if [[ "${OPT:5:1}" = "-" ]]; then if [[ "${OPT:5:1}" = "-" ]]; then
RG_ARGS+=("${OPT:5}") RG_ARGS+=("${OPT:5}")
@ -225,4 +240,3 @@ main() {
pager_exec main pager_exec main
exit $? exit $?

View File

@ -37,4 +37,3 @@ fi
command man "${MAN_ARGS[@]}" command man "${MAN_ARGS[@]}"
exit $? exit $?

View File

@ -45,7 +45,6 @@ watcher_entr_supported() {
return $? return $?
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POLL_STAT_VARIANT='' POLL_STAT_VARIANT=''
@ -162,13 +161,19 @@ fi
while shiftopt; do while shiftopt; do
case "$OPT" in case "$OPT" in
# Script Options # Script options
--watcher) shiftval; OPT_WATCHER="$OPT_VAL";; --watcher)
shiftval
OPT_WATCHER="$OPT_VAL"
;;
--clear) OPT_CLEAR=true ;; --clear) OPT_CLEAR=true ;;
--no-clear) OPT_CLEAR=false ;; --no-clear) OPT_CLEAR=false ;;
--terminal-width) shiftval; TERM_WIDTH="$OPT_VAL";; --terminal-width)
shiftval
TERM_WIDTH="$OPT_VAL"
;;
# Bat/Pager Options # bat/Pager options
-*) BAT_ARGS+=("$OPT=$OPT_VAL") ;; -*) BAT_ARGS+=("$OPT=$OPT_VAL") ;;
# Files # Files
@ -233,4 +238,3 @@ main() {
pager_exec main pager_exec main
exit $? exit $?

View File

@ -27,7 +27,8 @@ formatter_prettier_supports() {
.json | \ .json | \
.md | \ .md | \
.yml) .yml)
return 0;; return 0
;;
esac esac
return 1 return 1
@ -45,7 +46,8 @@ formatter_clangformat_supports() {
.c | .cpp | .cxx | \ .c | .cpp | .cxx | \
.h | .hpp | \ .h | .hpp | \
.m) .m)
return 0;; return 0
;;
esac esac
return 1 return 1
@ -80,8 +82,6 @@ formatter_shfmt_process() {
return $? return $?
} }
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Functions: # Functions:
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -199,12 +199,18 @@ FILES=()
while shiftopt; do while shiftopt; do
case "$OPT" in case "$OPT" in
# Language Options # Language options
-l) shiftval; OPT_LANGUAGE="${OPT_VAL}" ;; -l)
shiftval
OPT_LANGUAGE="${OPT_VAL}"
;;
-l*) OPT_LANGUAGE="${OPT:2}" ;; -l*) OPT_LANGUAGE="${OPT:2}" ;;
--language) shiftval; OPT_LANGUAGE="$OPT_VAL" ;; --language)
shiftval
OPT_LANGUAGE="$OPT_VAL"
;;
# Bat Options # bat options
-*) { -*) {
BAT_ARGS+=("$OPT=$OPT_VAL") BAT_ARGS+=("$OPT=$OPT_VAL")
} ;; } ;;
@ -231,4 +237,3 @@ done
# Exit. # Exit.
exit $EXIT exit $EXIT

View File

@ -25,7 +25,10 @@ export SNAPSHOT_DIR="${HERE}/test/snapshot"
OPT_ARGV=() OPT_ARGV=()
while shiftopt; do while shiftopt; do
case "$OPT" in case "$OPT" in
--compiled) TEST_ENV_BIN_DIR="${HERE}/bin"; TEST_ENV_BIN_SUFFIX="" ;; --compiled)
TEST_ENV_BIN_DIR="${HERE}/bin"
TEST_ENV_BIN_SUFFIX=""
;;
*) OPT_ARGV+=("$OPT") ;; *) OPT_ARGV+=("$OPT") ;;
esac esac
done done