mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-02-02 10:19:16 +01:00
Fix most of the errors and warnings reported by shellcheck
This commit is contained in:
parent
73aafa56e1
commit
f4765bfa54
10
build.sh
10
build.sh
@ -75,7 +75,8 @@ step_preprocess() {
|
|||||||
|
|
||||||
# Replace the DOCS_* variables.
|
# Replace the DOCS_* variables.
|
||||||
if [[ "$line" =~ ^DOCS_[A-Z]+=.*$ ]]; then
|
if [[ "$line" =~ ^DOCS_[A-Z]+=.*$ ]]; then
|
||||||
local docvar="$(cut -d'=' -f1 <<<"$line")"
|
local docvar
|
||||||
|
docvar="$(cut -d'=' -f1 <<<"$line")"
|
||||||
printf "%s=%q\n" "$docvar" "${!docvar}"
|
printf "%s=%q\n" "$docvar" "${!docvar}"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
@ -83,13 +84,13 @@ step_preprocess() {
|
|||||||
# Embed library scripts.
|
# Embed library scripts.
|
||||||
if [[ "$line" =~ ^[[:space:]]*source[[:space:]]+[\"\']\$\{?LIB\}/([a-z_-]+\.sh)[\"\'] ]]; then
|
if [[ "$line" =~ ^[[:space:]]*source[[:space:]]+[\"\']\$\{?LIB\}/([a-z_-]+\.sh)[\"\'] ]]; then
|
||||||
echo "# --- BEGIN LIBRARY FILE: ${BASH_REMATCH[1]} ---"
|
echo "# --- BEGIN LIBRARY FILE: ${BASH_REMATCH[1]} ---"
|
||||||
cat "$LIB/${BASH_REMATCH[1]}" | {
|
{
|
||||||
if [[ "$OPT_MINIFY" = "lib" ]]; then
|
if [[ "$OPT_MINIFY" = "lib" ]]; then
|
||||||
pp_strip_comments | pp_minify | pp_minify_unsafe
|
pp_strip_comments | pp_minify | pp_minify_unsafe
|
||||||
else
|
else
|
||||||
cat
|
cat
|
||||||
fi
|
fi
|
||||||
}
|
} <"$LIB/${BASH_REMATCH[1]}"
|
||||||
echo "# --- END LIBRARY FILE ---"
|
echo "# --- END LIBRARY FILE ---"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
@ -136,7 +137,8 @@ step_compress() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local wrapper="$({
|
local wrapper
|
||||||
|
wrapper="$({
|
||||||
printf '#!/usr/bin/env bash\n'
|
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"
|
printf "(exec -a \"\$0\" bash -c 'eval \"\$(cat <&3)\"' \"\$0\" \"\$@\" 3< <(dd bs=1 if=\"\$0\" skip=::: 2>/dev/null | gunzip)); exit \$?;\n"
|
||||||
})"
|
})"
|
||||||
|
@ -22,7 +22,8 @@ is_pager_disabled() {
|
|||||||
pager_name() {
|
pager_name() {
|
||||||
if [[ -z "${SCRIPT_PAGER_CMD[0]}" ]]; then return; fi
|
if [[ -z "${SCRIPT_PAGER_CMD[0]}" ]]; then return; fi
|
||||||
if [[ -z "$_SCRIPT_PAGER_NAME" ]]; then
|
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
|
if head -n 1 <<<"$output" | grep '^less \d' &>/dev/null; then
|
||||||
_SCRIPT_PAGER_NAME="less"
|
_SCRIPT_PAGER_NAME="less"
|
||||||
|
@ -8,10 +8,10 @@
|
|||||||
|
|
||||||
# Converts a string to lower case.
|
# Converts a string to lower case.
|
||||||
tolower() {
|
tolower() {
|
||||||
tr "[[:upper:]]" "[[:lower:]]" <<<"$1"
|
tr "[:upper:]" "[:lower:]" <<<"$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Converts a string to upper case.
|
# Converts a string to upper case.
|
||||||
toupper() {
|
toupper() {
|
||||||
tr "[[:lower:]]" "[[:upper:]]" <<<"$1"
|
tr "[:lower:]" "[:upper:]" <<<"$1"
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ if "$OPT_SEARCH_PATTERN"; then
|
|||||||
fi
|
fi
|
||||||
elif is_pager_disabled; then
|
elif is_pager_disabled; then
|
||||||
print_error "$(
|
print_error "$(
|
||||||
echo "The -p/--search-pattern option requires a pager, but" \
|
"The -p/--search-pattern option requires a pager, but" \
|
||||||
"the pager was explicitly disabled by \$BAT_PAGER or the" \
|
"the pager was explicitly disabled by \$BAT_PAGER or the" \
|
||||||
"--paging option."
|
"--paging option."
|
||||||
)"
|
)"
|
||||||
|
@ -21,16 +21,18 @@ BAT_ARGS=()
|
|||||||
|
|
||||||
while shiftopt; do MAN_ARGS+=("$OPT"); done
|
while shiftopt; do MAN_ARGS+=("$OPT"); done
|
||||||
if "$OPT_COLOR"; then
|
if "$OPT_COLOR"; then
|
||||||
BAT_ARGS="--color=always --decorations=always"
|
BAT_ARGS=("--color=always --decorations=always")
|
||||||
else
|
else
|
||||||
BAT_ARGS="--color=never --decorations=never"
|
BAT_ARGS=("--color=never --decorations=never")
|
||||||
fi
|
fi
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
export MANPAGER='sh -c "col -bx | '"$(printf "%q" "$BAT")"' --language=man --style=grid '"${BAT_ARGS[@]}"'"'
|
export MANPAGER
|
||||||
|
MANPAGER='sh -c "col -bx | '"$(printf "%q" "$BAT")"' --language=man --style=grid '"${BAT_ARGS[*]}"'"'
|
||||||
export MANROFFOPT='-c'
|
export MANROFFOPT='-c'
|
||||||
|
|
||||||
if [[ -n "${SCRIPT_PAGER_CMD}" ]]; then
|
if [[ -n "${SCRIPT_PAGER_CMD}" ]]; then
|
||||||
export BAT_PAGER="$(printf "%q " "${SCRIPT_PAGER_CMD[@]}" "${SCRIPT_PAGER_ARGS[@]}")"
|
export BAT_PAGER
|
||||||
|
BAT_PAGER="$(printf "%q " "${SCRIPT_PAGER_CMD[@]}" "${SCRIPT_PAGER_ARGS[@]}")"
|
||||||
else
|
else
|
||||||
unset BAT_PAGER
|
unset BAT_PAGER
|
||||||
fi
|
fi
|
||||||
|
@ -184,7 +184,7 @@ while shiftopt; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -z "$FILES" ]]; then
|
if [[ ${#FILES[@]} -eq 0 ]]; then
|
||||||
print_error "no files provided"
|
print_error "no files provided"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -213,7 +213,7 @@ fi
|
|||||||
# Determine the watcher.
|
# Determine the watcher.
|
||||||
if [[ -z "$OPT_WATCHER" ]]; then
|
if [[ -z "$OPT_WATCHER" ]]; then
|
||||||
OPT_WATCHER="$(determine_watcher)"
|
OPT_WATCHER="$(determine_watcher)"
|
||||||
if [[ $? -ne 0 ]]; then
|
if ! "$OPT_WATCHER"; then
|
||||||
print_error "Your system does not have any supported watchers."
|
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
|
printc "Please read the documentation at %{BLUE}%s%{CLEAR} for more details.\n" "$DOCS_URL/batwatch.md" 1>&2
|
||||||
exit 2
|
exit 2
|
||||||
|
@ -152,7 +152,8 @@ process_file() {
|
|||||||
fext="$(map_language_to_extension "$lang")"
|
fext="$(map_language_to_extension "$lang")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local formatter="$(map_extension_to_formatter "$fext")"
|
local formatter
|
||||||
|
formatter="$(map_extension_to_formatter "$fext")"
|
||||||
echo "FORMATTER >>> $formatter"
|
echo "FORMATTER >>> $formatter"
|
||||||
if [[ "$formatter" = "none" ]]; then
|
if [[ "$formatter" = "none" ]]; then
|
||||||
if [[ -z "$OPT_LANGUAGE" ]]; then
|
if [[ -z "$OPT_LANGUAGE" ]]; then
|
||||||
@ -170,14 +171,14 @@ process_file() {
|
|||||||
if [[ "$file" = "-" ]]; then
|
if [[ "$file" = "-" ]]; then
|
||||||
data_raw="$(cat -)"
|
data_raw="$(cat -)"
|
||||||
data_formatted="$("formatter_${formatter}_process" "$file" 2>/dev/null <<<"$data_raw")"
|
data_formatted="$("formatter_${formatter}_process" "$file" 2>/dev/null <<<"$data_raw")"
|
||||||
if [[ $? -ne 0 ]]; then
|
if "$data_formatted"; then
|
||||||
print_warning "'STDIN': Unable to format with '%s'" "$formatter"
|
print_warning "'STDIN': Unable to format with '%s'" "$formatter"
|
||||||
print_file --language="$lang" - <<<"$data_raw"
|
print_file --language="$lang" - <<<"$data_raw"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
data_formatted="$("formatter_${formatter}_process" "$file" <"$file")"
|
data_formatted="$("formatter_${formatter}_process" "$file" <"$file")"
|
||||||
if [[ $? -ne 0 ]]; then
|
if ! "$data_formatted"; then
|
||||||
print_warning "'%s': Unable to format with '%s'" "$file" "$formatter"
|
print_warning "'%s': Unable to format with '%s'" "$file" "$formatter"
|
||||||
print_file --language="$lang" "$file"
|
print_file --language="$lang" "$file"
|
||||||
return 1
|
return 1
|
||||||
@ -224,7 +225,7 @@ while shiftopt; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [[ "${#FILES[@]}" -eq 0 ]]; then
|
if [[ "${#FILES[@]}" -eq 0 ]]; then
|
||||||
FILES="-"
|
FILES=("-")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Handle input files.
|
# Handle input files.
|
||||||
@ -236,4 +237,4 @@ for file in "${FILES[@]}"; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Exit.
|
# Exit.
|
||||||
exit $EXIT
|
exit "$EXIT"
|
||||||
|
2
test.sh
2
test.sh
@ -9,7 +9,7 @@ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|||||||
LIB="${HERE}/lib"
|
LIB="${HERE}/lib"
|
||||||
source "${LIB}/opt.sh"
|
source "${LIB}/opt.sh"
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
cd "$HERE"
|
cd "$HERE" || exit
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
export TEST_ENV_LIB="${HERE}/lib"
|
export TEST_ENV_LIB="${HERE}/lib"
|
||||||
|
Loading…
Reference in New Issue
Block a user