mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-08-17 08:00:56 +02:00
Merge pull request #15 from VeryTastyTomato/master
Fix most of warnings reported by ShellCheck and format files
This commit is contained in:
@ -40,7 +40,6 @@ commands:
|
||||
name: "Build"
|
||||
command: ./build.sh --minify=<<parameters.minify>> --no-verify
|
||||
|
||||
|
||||
jobs:
|
||||
build:
|
||||
executor: linux_alpine
|
||||
@ -97,4 +96,3 @@ workflows:
|
||||
requires: [build, test]
|
||||
- test-symlink:
|
||||
requires: [build]
|
||||
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,4 +10,3 @@
|
||||
/.circleci/.config.yml
|
||||
.download
|
||||
bin
|
||||
|
||||
|
1
.gitmodules
vendored
1
.gitmodules
vendored
@ -1,4 +1,3 @@
|
||||
[submodule "best"]
|
||||
path = .test-framework
|
||||
url = https://github.com/eth-p/best.git
|
||||
|
||||
|
34
build.sh
34
build.sh
@ -63,6 +63,7 @@ step_read() {
|
||||
# The processed file contents.
|
||||
step_preprocess() {
|
||||
local line
|
||||
local docvar
|
||||
while IFS='' read -r line; do
|
||||
# Skip certain lines.
|
||||
[[ "$line" =~ ^LIB=.*$ ]] && continue
|
||||
@ -75,7 +76,7 @@ step_preprocess() {
|
||||
|
||||
# Replace the DOCS_* variables.
|
||||
if [[ "$line" =~ ^DOCS_[A-Z]+=.*$ ]]; then
|
||||
local docvar="$(cut -d'=' -f1 <<< "$line")"
|
||||
docvar="$(cut -d'=' -f1 <<<"$line")"
|
||||
printf "%s=%q\n" "$docvar" "${!docvar}"
|
||||
continue
|
||||
fi
|
||||
@ -83,13 +84,13 @@ step_preprocess() {
|
||||
# Embed library scripts.
|
||||
if [[ "$line" =~ ^[[:space:]]*source[[:space:]]+[\"\']\$\{?LIB\}/([a-z_-]+\.sh)[\"\'] ]]; then
|
||||
echo "# --- BEGIN LIBRARY FILE: ${BASH_REMATCH[1]} ---"
|
||||
cat "$LIB/${BASH_REMATCH[1]}" | {
|
||||
{
|
||||
if [[ "$OPT_MINIFY" = "lib" ]]; then
|
||||
pp_strip_comments | pp_minify | pp_minify_unsafe
|
||||
else
|
||||
cat
|
||||
fi
|
||||
}
|
||||
} <"$LIB/${BASH_REMATCH[1]}"
|
||||
echo "# --- END LIBRARY FILE ---"
|
||||
continue
|
||||
fi
|
||||
@ -136,12 +137,13 @@ step_compress() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
local wrapper="$({
|
||||
local wrapper
|
||||
wrapper="$({
|
||||
printf '#!/usr/bin/env bash\n'
|
||||
printf "(exec -a \"\$0\" bash -c 'eval \"\$(cat <&3)\"' \"\$0\" \"\$@\" 3< <(dd bs=1 if=\"\$0\" skip=::: 2>/dev/null | gunzip)); exit \$?;\n"
|
||||
})"
|
||||
|
||||
sed "s/:::/$(wc -c <<< "$wrapper" | bc)/" <<< "$wrapper"
|
||||
echo "${wrapper/:::/$(wc -c <<<"$wrapper" | sed 's/^[[:space:]]*//')}"
|
||||
gzip
|
||||
smsg "Compressing"
|
||||
}
|
||||
@ -232,6 +234,7 @@ DOCS_URL="https://github.com/eth-p/bat-extras/blob/master/doc"
|
||||
DOCS_MAINTAINER="eth-p <eth-p@hidden.email>"
|
||||
|
||||
while shiftopt; do
|
||||
# shellcheck disable=SC2034
|
||||
case "$OPT" in
|
||||
--install) OPT_INSTALL=true ;;
|
||||
--compress) OPT_COMPRESS=true ;;
|
||||
@ -242,8 +245,10 @@ while shiftopt; do
|
||||
--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
|
||||
done
|
||||
|
||||
@ -290,17 +295,17 @@ printc "%{YELLOW}Building scripts...%{CLEAR}\n" 1>&2
|
||||
file_i=0
|
||||
file_n="${#SOURCES[@]}"
|
||||
for file in "${SOURCES[@]}"; do
|
||||
((file_i++)) || true;
|
||||
((file_i++)) || true
|
||||
|
||||
filename="$(basename "$file" .sh)"
|
||||
|
||||
printc " %{YELLOW}[%s/%s] %{MAGENTA}%s%{CLEAR}\n" "$file_i" "$file_n" "$file" 1>&2
|
||||
step_read "$file" |\
|
||||
next step_preprocess |\
|
||||
next step_minify |\
|
||||
next step_compress |\
|
||||
next step_write "${BIN}/${filename}" |\
|
||||
next step_write_install "${OPT_PREFIX}/bin/${filename}" |\
|
||||
step_read "$file" |
|
||||
next step_preprocess |
|
||||
next step_minify |
|
||||
next step_compress |
|
||||
next step_write "${BIN}/${filename}" |
|
||||
next step_write_install "${OPT_PREFIX}/bin/${filename}" |
|
||||
cat >/dev/null
|
||||
done
|
||||
|
||||
@ -312,4 +317,3 @@ if "$OPT_VERIFY"; then
|
||||
"${HERE}/test.sh" --compiled
|
||||
exit $?
|
||||
fi
|
||||
|
||||
|
@ -53,7 +53,6 @@ shiftopt() {
|
||||
fi
|
||||
done
|
||||
|
||||
# Return.
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -81,7 +80,5 @@ shiftval() {
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
setargs "$@"
|
||||
|
||||
|
@ -6,13 +6,12 @@
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Hooks:
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# 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.
|
||||
#
|
||||
# The variable OPT_COLOR will be set depending on whether or not a TTY is
|
||||
@ -21,17 +20,22 @@ hook_color() {
|
||||
SHIFTOPT_HOOKS+=("__shiftopt_hook__color")
|
||||
__shiftopt_hook__color() {
|
||||
case "$OPT" in
|
||||
--no-color) OPT_COLOR=false; printc_init "$OPT_COLOR";;
|
||||
|
||||
--no-color) OPT_COLOR=false ;;
|
||||
--color) {
|
||||
case "$OPT_VAL" in
|
||||
auto) :;;
|
||||
always|true) OPT_COLOR=true; printc_init "$OPT_COLOR";;
|
||||
never|false) OPT_COLOR=false; printc_init "$OPT_COLOR";;
|
||||
always | true) OPT_COLOR=true ;;
|
||||
never | false) OPT_COLOR=false ;;
|
||||
|
||||
auto) return 0 ;;
|
||||
esac
|
||||
} ;;
|
||||
|
||||
*) return 1 ;;
|
||||
esac
|
||||
|
||||
printc_init "$OPT_COLOR"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Default color support.
|
||||
@ -51,25 +55,32 @@ hook_pager() {
|
||||
SHIFTOPT_HOOKS+=("__shiftopt_hook__pager")
|
||||
__shiftopt_hook__pager() {
|
||||
case "$OPT" in
|
||||
|
||||
# Specify paging.
|
||||
--no-pager) shiftval; SCRIPT_PAGER_CMD='' ;;
|
||||
--paging) shiftval; {
|
||||
--paging) {
|
||||
shiftval
|
||||
|
||||
case "$OPT_VAL" in
|
||||
auto) : ;;
|
||||
never) SCRIPT_PAGER_CMD='';;
|
||||
always) : ;;
|
||||
never) SCRIPT_PAGER_CMD='' ;;
|
||||
esac
|
||||
} ;;
|
||||
|
||||
# Specify the pager.
|
||||
--pager) {
|
||||
shiftval;
|
||||
SCRIPT_PAGER_CMD=($OPT_VAL);
|
||||
shiftval
|
||||
|
||||
# [note]: These are both intentional.
|
||||
# shellcheck disable=SC2034 disable=SC2206
|
||||
{
|
||||
SCRIPT_PAGER_CMD=($OPT_VAL)
|
||||
PAGER_ARGS=()
|
||||
}
|
||||
} ;;
|
||||
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
}
|
||||
|
||||
|
14
lib/pager.sh
14
lib/pager.sh
@ -6,13 +6,13 @@
|
||||
# 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() {
|
||||
[[ "$(pager_name)" = "less" ]]
|
||||
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() {
|
||||
[[ -z "$(pager_name)" ]]
|
||||
return $?
|
||||
@ -22,7 +22,8 @@ is_pager_disabled() {
|
||||
pager_name() {
|
||||
if [[ -z "${SCRIPT_PAGER_CMD[0]}" ]]; then return; fi
|
||||
if [[ -z "$_SCRIPT_PAGER_NAME" ]]; then
|
||||
local output="$("${SCRIPT_PAGER_CMD[0]}" --version 2>&1)"
|
||||
local output
|
||||
output="$("${SCRIPT_PAGER_CMD[0]}" --version 2>&1)"
|
||||
|
||||
if head -n 1 <<<"$output" | grep '^less \d' &>/dev/null; then
|
||||
_SCRIPT_PAGER_NAME="less"
|
||||
@ -34,7 +35,7 @@ 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.
|
||||
# Example:
|
||||
@ -51,7 +52,7 @@ pager_exec() {
|
||||
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:
|
||||
# bat | pager_display
|
||||
@ -76,6 +77,8 @@ fi
|
||||
|
||||
# Prefer the bat pager.
|
||||
if [[ -n "${BAT_PAGER+x}" ]]; then
|
||||
# [note]: This is intentional.
|
||||
# shellcheck disable=SC2206
|
||||
SCRIPT_PAGER_CMD=($BAT_PAGER)
|
||||
SCRIPT_PAGER_ARGS=()
|
||||
fi
|
||||
@ -85,4 +88,3 @@ if ! [[ -t 1 ]]; then
|
||||
SCRIPT_PAGER_CMD=()
|
||||
SCRIPT_PAGER_ARGS=()
|
||||
fi
|
||||
|
||||
|
11
lib/print.sh
11
lib/print.sh
@ -26,7 +26,7 @@ printc_init() {
|
||||
true) _PRINTC_PATTERN="$_PRINTC_PATTERN_ANSI" ;;
|
||||
false) _PRINTC_PATTERN="$_PRINTC_PATTERN_PLAIN" ;;
|
||||
|
||||
"") {
|
||||
"[DEFINE]") {
|
||||
_PRINTC_PATTERN_ANSI=""
|
||||
_PRINTC_PATTERN_PLAIN=""
|
||||
|
||||
@ -37,7 +37,7 @@ printc_init() {
|
||||
continue
|
||||
fi
|
||||
|
||||
ansi="$(sed 's/\\/\\\\/' <<< "$ansi")"
|
||||
ansi="${ansi/\\/\\\\}"
|
||||
|
||||
_PRINTC_PATTERN_PLAIN="${_PRINTC_PATTERN_PLAIN}s/%{${name}}//g;"
|
||||
_PRINTC_PATTERN_ANSI="${_PRINTC_PATTERN_ANSI}s/%{${name}}/${ansi}/g;"
|
||||
@ -52,7 +52,7 @@ printc_init() {
|
||||
esac
|
||||
}
|
||||
|
||||
# Print a warning message to STDERR.
|
||||
# Print a warning message to stderr.
|
||||
# Arguments:
|
||||
# 1 -- The printc formatting string.
|
||||
# ... -- The printc formatting arguments.
|
||||
@ -60,7 +60,7 @@ print_warning() {
|
||||
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:
|
||||
# 1 -- The printc formatting string.
|
||||
# ... -- The printc formatting arguments.
|
||||
@ -71,7 +71,7 @@ print_error() {
|
||||
# -----------------------------------------------------------------------------
|
||||
# Initialization:
|
||||
# -----------------------------------------------------------------------------
|
||||
printc_init <<END
|
||||
printc_init "[DEFINE]" <<END
|
||||
CLEAR \x1B[0m
|
||||
RED \x1B[31m
|
||||
GREEN \x1B[32m
|
||||
@ -82,4 +82,3 @@ printc_init <<END
|
||||
|
||||
DIM \x1B[2m
|
||||
END
|
||||
|
||||
|
@ -8,11 +8,10 @@
|
||||
|
||||
# Converts a string to lower case.
|
||||
tolower() {
|
||||
tr "[[:upper:]]" "[[:lower:]]" <<< "$1"
|
||||
tr "[:upper:]" "[:lower:]" <<<"$1"
|
||||
}
|
||||
|
||||
# Converts a string to upper case.
|
||||
toupper() {
|
||||
tr "[[:lower:]]" "[[:upper:]]" <<< "$1"
|
||||
tr "[:lower:]" "[:upper:]" <<<"$1"
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ version_compare__recurse() {
|
||||
# Compare the versions specially if the final number has been reached.
|
||||
if [[ -z "$v_minor" && -z "$c_minor" ]]; then
|
||||
[ "$v_major" $operator "$c_major" ];
|
||||
return $?;
|
||||
return $?
|
||||
fi
|
||||
|
||||
# Insert zeroes where there are missing numbers.
|
||||
@ -66,13 +66,11 @@ version_compare__recurse() {
|
||||
case "$operator" in
|
||||
-eq) [[ "$v_major" -ne "$c_major" ]] && return 1 ;;
|
||||
-ne) [[ "$v_major" -ne "$c_major" ]] && return 0 ;;
|
||||
-ge|-gt) [[ "$v_major" -lt "$c_major" ]] && return 1;
|
||||
-ge | -gt) [[ "$v_major" -lt "$c_major" ]] && return 1
|
||||
[[ "$v_major" -gt "$c_major" ]] && return 0 ;;
|
||||
-le|-lt) [[ "$v_major" -gt "$c_major" ]] && return 1;
|
||||
-le | -lt) [[ "$v_major" -gt "$c_major" ]] && return 1
|
||||
[[ "$v_major" -lt "$c_major" ]] && return 0 ;;
|
||||
esac
|
||||
|
||||
version_compare__recurse "$v_minor" "$operator" "$c_minor"
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
# Repository: https://github.com/eth-p/bat-extras
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
# -----------------------------------------------------------------------------
|
||||
# shellcheck disable=SC1090
|
||||
LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo ".")")/../lib" && pwd)"
|
||||
BAT="bat"
|
||||
source "${LIB}/print.sh"
|
||||
@ -43,16 +44,23 @@ fi
|
||||
while shiftopt; do
|
||||
case "$OPT" in
|
||||
|
||||
# Ripgrep Options
|
||||
# ripgrep options
|
||||
-i | --ignore-case) OPT_CASE_SENSITIVITY="--ignore-case" ;;
|
||||
-s | --case-sensitive) OPT_CASE_SENSITIVITY="--case-sensitive" ;;
|
||||
-S | --smart-case) OPT_CASE_SENSITIVITY="--smart-case" ;;
|
||||
-A | --after-context) shiftval; 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");;
|
||||
-C | --context)
|
||||
shiftval
|
||||
OPT_CONTEXT_BEFORE="$OPT_VAL"
|
||||
OPT_CONTEXT_AFTER="$OPT_VAL"
|
||||
;;
|
||||
|
||||
-F | --fixed-strings)
|
||||
OPT_FIXED_STRINGS=true
|
||||
RG_ARGS+=("$OPT")
|
||||
;;
|
||||
|
||||
-U | --multiline | \
|
||||
-P | --pcre2 | \
|
||||
@ -62,7 +70,9 @@ while shiftopt; do
|
||||
--multiline-dotall | \
|
||||
--ignore | --no-ignore | \
|
||||
--crlf | --no-crlf | \
|
||||
--hidden|--no-hidden) RG_ARGS+=("$OPT");;
|
||||
--hidden | --no-hidden)
|
||||
RG_ARGS+=("$OPT")
|
||||
;;
|
||||
|
||||
-E | --encoding | \
|
||||
-g | --glob | \
|
||||
@ -71,18 +81,21 @@ while shiftopt; do
|
||||
-m | --max-count | \
|
||||
--max-depth | \
|
||||
--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-snip) OPT_SNIP="" ;;
|
||||
--no-highlight) OPT_HIGHLIGHT=false ;;
|
||||
-p | --search-pattern) OPT_SEARCH_PATTERN=true ;;
|
||||
--no-search-pattern) OPT_SEARCH_PATTERN=false ;;
|
||||
|
||||
# Option Forwarding
|
||||
# Option forwarding
|
||||
--rg:*) {
|
||||
if [[ "${OPT:5:1}" = "-" ]]; then
|
||||
RG_ARGS+=("${OPT:5}")
|
||||
@ -108,6 +121,7 @@ while shiftopt; do
|
||||
FILES+=("$OPT")
|
||||
fi
|
||||
} ;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
@ -153,11 +167,10 @@ if "$OPT_SEARCH_PATTERN"; then
|
||||
SCRIPT_PAGER_ARGS+=(-p "$PATTERN")
|
||||
fi
|
||||
elif is_pager_disabled; then
|
||||
print_error "$(
|
||||
echo "The -p/--search-pattern option requires a pager, but" \
|
||||
print_error "%s %s %s" \
|
||||
"The -p/--search-pattern option requires a pager, but" \
|
||||
"the pager was explicitly disabled by \$BAT_PAGER or the" \
|
||||
"--paging option."
|
||||
)"
|
||||
exit 1
|
||||
else
|
||||
print_error "Unsupported pager '%s' for option -p/--search-pattern" \
|
||||
@ -170,6 +183,7 @@ fi
|
||||
# Main:
|
||||
# -----------------------------------------------------------------------------
|
||||
main() {
|
||||
# shellcheck disable=SC2034
|
||||
FOUND_FILES=()
|
||||
FOUND=0
|
||||
FIRST_PRINT=true
|
||||
@ -197,6 +211,7 @@ main() {
|
||||
echo "$SEP"
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
while IFS=':' read -r file line column; do
|
||||
((FOUND++))
|
||||
|
||||
@ -225,4 +240,3 @@ main() {
|
||||
|
||||
pager_exec main
|
||||
exit $?
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
# Repository: https://github.com/eth-p/bat-extras
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
# -----------------------------------------------------------------------------
|
||||
# shellcheck disable=SC1090 disable=SC2155
|
||||
LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo ".")")/../lib" && pwd)"
|
||||
BAT="bat"
|
||||
if [[ -n "${MANPAGER}" ]]; then BAT_PAGER="$MANPAGER"; fi
|
||||
@ -21,12 +22,12 @@ BAT_ARGS=()
|
||||
|
||||
while shiftopt; do MAN_ARGS+=("$OPT"); done
|
||||
if "$OPT_COLOR"; then
|
||||
BAT_ARGS="--color=always --decorations=always"
|
||||
BAT_ARGS=("--color=always --decorations=always")
|
||||
else
|
||||
BAT_ARGS="--color=never --decorations=never"
|
||||
BAT_ARGS=("--color=never --decorations=never")
|
||||
fi
|
||||
# -----------------------------------------------------------------------------
|
||||
export MANPAGER='sh -c "col -bx | '"$(printf "%q" "$BAT")"' --language=man --style=grid '"${BAT_ARGS[@]}"'"'
|
||||
export MANPAGER='sh -c "col -bx | '"$(printf "%q" "$BAT")"' --language=man --style=grid '"${BAT_ARGS[*]}"'"'
|
||||
export MANROFFOPT='-c'
|
||||
|
||||
if [[ -n "${SCRIPT_PAGER_CMD}" ]]; then
|
||||
@ -37,4 +38,3 @@ fi
|
||||
|
||||
command man "${MAN_ARGS[@]}"
|
||||
exit $?
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
# Repository: https://github.com/eth-p/bat-extras
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
# -----------------------------------------------------------------------------
|
||||
# shellcheck disable=SC1090
|
||||
LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo ".")")/../lib" && pwd)"
|
||||
BAT="bat"
|
||||
DOCS_URL="https://github.com/eth-p/bat-extras/blob/master/doc"
|
||||
@ -45,7 +46,6 @@ watcher_entr_supported() {
|
||||
return $?
|
||||
}
|
||||
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
POLL_STAT_VARIANT=''
|
||||
@ -162,13 +162,13 @@ fi
|
||||
while shiftopt; do
|
||||
case "$OPT" in
|
||||
|
||||
# Script Options
|
||||
# Script options
|
||||
--watcher) shiftval; OPT_WATCHER="$OPT_VAL" ;;
|
||||
--clear) OPT_CLEAR=true ;;
|
||||
--no-clear) OPT_CLEAR=false ;;
|
||||
--terminal-width) shiftval; TERM_WIDTH="$OPT_VAL" ;;
|
||||
|
||||
# Bat/Pager Options
|
||||
# bat/Pager options
|
||||
-*) BAT_ARGS+=("$OPT=$OPT_VAL") ;;
|
||||
|
||||
# Files
|
||||
@ -179,7 +179,7 @@ while shiftopt; do
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z "$FILES" ]]; then
|
||||
if [[ ${#FILES[@]} -eq 0 ]]; then
|
||||
print_error "no files provided"
|
||||
exit 1
|
||||
fi
|
||||
@ -207,8 +207,7 @@ fi
|
||||
# -----------------------------------------------------------------------------
|
||||
# Determine the watcher.
|
||||
if [[ -z "$OPT_WATCHER" ]]; then
|
||||
OPT_WATCHER="$(determine_watcher)"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
if ! OPT_WATCHER="$(determine_watcher)"; then
|
||||
print_error "Your system does not have any supported watchers."
|
||||
printc "Please read the documentation at %{BLUE}%s%{CLEAR} for more details.\n" "$DOCS_URL/batwatch.md" 1>&2
|
||||
exit 2
|
||||
@ -233,4 +232,3 @@ main() {
|
||||
|
||||
pager_exec main
|
||||
exit $?
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
# Repository: https://github.com/eth-p/bat-extras
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
# -----------------------------------------------------------------------------
|
||||
# shellcheck disable=SC1090
|
||||
LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo ".")")/../lib" && pwd)"
|
||||
BAT="bat"
|
||||
source "${LIB}/opt.sh"
|
||||
@ -27,7 +28,8 @@ formatter_prettier_supports() {
|
||||
.json | \
|
||||
.md | \
|
||||
.yml)
|
||||
return 0;;
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
return 1
|
||||
@ -45,7 +47,8 @@ formatter_clangformat_supports() {
|
||||
.c | .cpp | .cxx | \
|
||||
.h | .hpp | \
|
||||
.m)
|
||||
return 0;;
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
return 1
|
||||
@ -80,8 +83,6 @@ formatter_shfmt_process() {
|
||||
return $?
|
||||
}
|
||||
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Functions:
|
||||
# -----------------------------------------------------------------------------
|
||||
@ -146,13 +147,14 @@ process_file() {
|
||||
local ext="$2"
|
||||
local fext="$ext"
|
||||
local lang="${ext:1}"
|
||||
local formatter
|
||||
|
||||
if [[ -n "$OPT_LANGUAGE" ]]; then
|
||||
lang="$OPT_LANGUAGE"
|
||||
fext="$(map_language_to_extension "$lang")"
|
||||
fi
|
||||
|
||||
local formatter="$(map_extension_to_formatter "$fext")"
|
||||
formatter="$(map_extension_to_formatter "$fext")"
|
||||
echo "FORMATTER >>> $formatter"
|
||||
if [[ "$formatter" = "none" ]]; then
|
||||
if [[ -z "$OPT_LANGUAGE" ]]; then
|
||||
@ -164,12 +166,14 @@ process_file() {
|
||||
fi
|
||||
|
||||
# Prettify, then print.
|
||||
local status
|
||||
local data_raw
|
||||
local data_formatted
|
||||
|
||||
# shellcheck disable=SC2094 disable=SC2181
|
||||
if [[ "$file" = "-" ]]; then
|
||||
data_raw="$(cat -)"
|
||||
data_formatted="$("formatter_${formatter}_process" "$file" 2>/dev/null <<<"$data_raw")"
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
print_warning "'STDIN': Unable to format with '%s'" "$formatter"
|
||||
print_file --language="$lang" - <<<"$data_raw"
|
||||
@ -177,6 +181,7 @@ process_file() {
|
||||
fi
|
||||
else
|
||||
data_formatted="$("formatter_${formatter}_process" "$file" <"$file")"
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
print_warning "'%s': Unable to format with '%s'" "$file" "$formatter"
|
||||
print_file --language="$lang" "$file"
|
||||
@ -199,12 +204,12 @@ FILES=()
|
||||
while shiftopt; do
|
||||
case "$OPT" in
|
||||
|
||||
# Language Options
|
||||
# Language options
|
||||
-l) shiftval; OPT_LANGUAGE="${OPT_VAL}" ;;
|
||||
-l*) OPT_LANGUAGE="${OPT:2}" ;;
|
||||
--language) shiftval; OPT_LANGUAGE="$OPT_VAL" ;;
|
||||
|
||||
# Bat Options
|
||||
# bat options
|
||||
-*) {
|
||||
BAT_ARGS+=("$OPT=$OPT_VAL")
|
||||
} ;;
|
||||
@ -218,7 +223,7 @@ while shiftopt; do
|
||||
done
|
||||
|
||||
if [[ "${#FILES[@]}" -eq 0 ]]; then
|
||||
FILES="-"
|
||||
FILES=("-")
|
||||
fi
|
||||
|
||||
# Handle input files.
|
||||
@ -230,5 +235,4 @@ for file in "${FILES[@]}"; do
|
||||
done
|
||||
|
||||
# Exit.
|
||||
exit $EXIT
|
||||
|
||||
exit "$FAIL"
|
||||
|
7
test.sh
7
test.sh
@ -9,7 +9,7 @@ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
LIB="${HERE}/lib"
|
||||
source "${LIB}/opt.sh"
|
||||
# -----------------------------------------------------------------------------
|
||||
cd "$HERE"
|
||||
cd "$HERE" || exit
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
export TEST_ENV_LIB="${HERE}/lib"
|
||||
@ -25,7 +25,10 @@ export SNAPSHOT_DIR="${HERE}/test/snapshot"
|
||||
OPT_ARGV=()
|
||||
while shiftopt; do
|
||||
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") ;;
|
||||
esac
|
||||
done
|
||||
|
@ -7,4 +7,3 @@ clocks
|
||||
bash
|
||||
$300
|
||||
^$!@
|
||||
|
||||
|
Reference in New Issue
Block a user