aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Fink2026-05-22 22:13:57 +0200
committerDennis Fink2026-05-22 22:13:57 +0200
commit70ca25e5b8cf72a30743170876f2565bc4c052fe (patch)
treecd7b0bbe20ee45c8ac9e4e1b0cd073446c92d03a
parente6df883f8bb16e24705db1937a0d1d62cef4ae9d (diff)
downloadtranscode.sh-70ca25e5b8cf72a30743170876f2565bc4c052fe.tar.gz
transcode.sh-70ca25e5b8cf72a30743170876f2565bc4c052fe.zip
style(shell): use function keyword consistently
Add the function keyword to shell function definitions across the main script, developer scripts, and bash completion file. This makes function declarations visually consistent throughout the project and easier to scan without changing behavior.
Diffstat (limited to '')
-rwxr-xr-xdevscripts/generate-testfile.sh36
-rwxr-xr-xdevscripts/release.sh50
-rwxr-xr-xtranscode.sh60
-rw-r--r--transcode.sh.bash-completion.sh4
4 files changed, 75 insertions, 75 deletions
diff --git a/devscripts/generate-testfile.sh b/devscripts/generate-testfile.sh
index e8bcbe8..fab91cd 100755
--- a/devscripts/generate-testfile.sh
+++ b/devscripts/generate-testfile.sh
@@ -125,7 +125,7 @@ readonly EXIT_OK EXIT_RUNTIME_FAILURE EXIT_USAGE_ERROR EXIT_CONFIG_ERROR EXIT_MI
# OUTPUT HELPERS
###############################################################################
-emit() {
+function emit() {
local prefix="$1"
local color="$2"
shift 2
@@ -151,29 +151,29 @@ emit() {
printf "\n"
}
-error() {
+function error() {
emit "==> ERROR:" "$RED" "$@" >&2
}
-msg() {
+function msg() {
if [[ $QUIET -eq 0 ]]; then
emit "==>" "$GREEN" "$@"
fi
}
-warn() {
+function warn() {
if [[ $QUIET -eq 0 ]]; then
emit "==>" "$YELLOW" "$@"
fi
}
-verbose() {
+function verbose() {
if [[ $VERBOSE -eq 1 && $QUIET -eq 0 ]]; then
emit "==>" "$BLUE" "$@"
fi
}
-debug() {
+function debug() {
if [[ $DEBUG -eq 1 ]]; then
emit "==> DEBUG:" "$MAGENTA" "$@"
fi
@@ -183,7 +183,7 @@ debug() {
# HELP AND VERSION OUTPUT
###############################################################################
-print_help() {
+function print_help() {
printf "${BOLD}${MAGENTA}%s${ALL_OFF} - ${BOLD}${CYAN}%s${ALL_OFF} - ${BOLD}%s${ALL_OFF}
${BOLD}${BLUE}Usage:${ALL_OFF} ${BOLD}${MAGENTA}%s${ALL_OFF} ${BOLD}${YELLOW}[OPTION]...${ALL_OFF} ${BOLD}${GREEN}[OUTPUT]${ALL_OFF}
@@ -221,7 +221,7 @@ ${BOLD}${BLUE}Examples:${ALL_OFF}
"$SCRIPTNAME" "$SCRIPTNAME" "$SCRIPTNAME" "$SCRIPTNAME"
}
-print_version() {
+function print_version() {
printf "${RED}${BOLD}Scriptname:${ALL_OFF} %s
${GREEN}${BOLD}Version:${ALL_OFF} %s
${YELLOW}${BOLD}Description:${ALL_OFF} %s
@@ -272,7 +272,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" \
# disabled. If FORCE_COLOR is set, colors are always enabled.
###############################################################################
-setup_colors() {
+function setup_colors() {
if [[ "$ENABLE_COLOR" -eq 1 ]]; then
if tput setaf 0 >/dev/null 2>&1; then
debug "Setting colors via tput"
@@ -313,7 +313,7 @@ setup_colors() {
# GENERATION HELPERS
###############################################################################
-require_command() {
+function require_command() {
local command_name="$1"
command -v "$command_name" >/dev/null 2>&1 || {
@@ -322,28 +322,28 @@ require_command() {
}
}
-validate_resolution() {
+function validate_resolution() {
if [[ ! "$RESOLUTION" =~ ^[1-9][0-9]*x[1-9][0-9]*$ ]]; then
error "Resolution must use WIDTHxHEIGHT format:" "$RESOLUTION"
exit $EXIT_USAGE_ERROR
fi
}
-validate_length() {
+function validate_length() {
if [[ "$LENGTH" =~ ^- ]]; then
error "Length must be a positive ffmpeg duration:" "$LENGTH"
exit $EXIT_USAGE_ERROR
fi
}
-validate_frame_rate() {
+function validate_frame_rate() {
if [[ ! "$FRAME_RATE" =~ ^[1-9][0-9]*([.][0-9]+)?$ ]]; then
error "Frame rate must be a positive number:" "$FRAME_RATE"
exit $EXIT_USAGE_ERROR
fi
}
-extension_for_codec() {
+function extension_for_codec() {
case "$CODEC" in
libvpx | libvpx-vp9)
printf "webm"
@@ -357,7 +357,7 @@ extension_for_codec() {
esac
}
-sanitized_name_part() {
+function sanitized_name_part() {
local value="$1"
value="${value//\//-}"
value="${value//:/-}"
@@ -365,7 +365,7 @@ sanitized_name_part() {
printf "%s" "$value"
}
-default_output_path() {
+function default_output_path() {
local extension codec_part length_part
extension="$(extension_for_codec)"
codec_part="$(sanitized_name_part "$CODEC")"
@@ -374,13 +374,13 @@ default_output_path() {
printf "%s/%s-%s-%ss.%s" "$OUTPUT_DIR" "$codec_part" "$RESOLUTION" "$length_part" "$extension"
}
-print_command() {
+function print_command() {
local quoted_command
printf -v quoted_command '%q ' "${FFMPEG_COMMAND[@]}"
printf "%s\n" "${quoted_command% }"
}
-generate_test_file() {
+function generate_test_file() {
local output_file="$1"
if [[ -e "$output_file" && $OVERWRITE -eq 0 ]]; then
diff --git a/devscripts/release.sh b/devscripts/release.sh
index 0fda106..8ef1bd0 100755
--- a/devscripts/release.sh
+++ b/devscripts/release.sh
@@ -119,7 +119,7 @@ readonly EXIT_OK EXIT_RUNTIME_FAILURE EXIT_USAGE_ERROR EXIT_CONFIG_ERROR EXIT_MI
# OUTPUT HELPERS
###############################################################################
-emit() {
+function emit() {
local prefix="$1"
local color="$2"
shift 2
@@ -145,29 +145,29 @@ emit() {
printf "\n"
}
-error() {
+function error() {
emit "==> ERROR:" "$RED" "$@" >&2
}
-msg() {
+function msg() {
if [[ $QUIET -eq 0 ]]; then
emit "==>" "$GREEN" "$@"
fi
}
-warn() {
+function warn() {
if [[ $QUIET -eq 0 ]]; then
emit "==>" "$YELLOW" "$@"
fi
}
-verbose() {
+function verbose() {
if [[ $VERBOSE -eq 1 && $QUIET -eq 0 ]]; then
emit "==>" "$BLUE" "$@"
fi
}
-debug() {
+function debug() {
if [[ $DEBUG -eq 1 ]]; then
emit "==> DEBUG:" "$MAGENTA" "$@"
fi
@@ -177,7 +177,7 @@ debug() {
# HELP AND VERSION OUTPUT
###############################################################################
-print_help() {
+function print_help() {
printf "${BOLD}${MAGENTA}%s${ALL_OFF} - ${BOLD}${CYAN}%s${ALL_OFF} - ${BOLD}%s${ALL_OFF}
${BOLD}${BLUE}Usage:${ALL_OFF} ${BOLD}${MAGENTA}%s${ALL_OFF} ${BOLD}${YELLOW}[OPTION]...${ALL_OFF} ${BOLD}${GREEN}COMMAND VERSION${ALL_OFF}
@@ -213,7 +213,7 @@ ${BOLD}${BLUE}Notes:${ALL_OFF}
"$SCRIPTNAME" "$SCRIPTNAME" "$SCRIPTNAME" "$DIST_DIR"
}
-print_version() {
+function print_version() {
printf "${RED}${BOLD}Scriptname:${ALL_OFF} %s
${GREEN}${BOLD}Version:${ALL_OFF} %s
${YELLOW}${BOLD}Description:${ALL_OFF} %s
@@ -264,7 +264,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" \
# disabled. If FORCE_COLOR is set, colors are always enabled.
###############################################################################
-setup_colors() {
+function setup_colors() {
if [[ "$ENABLE_COLOR" -eq 1 ]]; then
if tput setaf 0 >/dev/null 2>&1; then
debug "Setting colors via tput"
@@ -305,7 +305,7 @@ setup_colors() {
# RELEASE HELPERS
###############################################################################
-require_command() {
+function require_command() {
local command_name="$1"
command -v "$command_name" >/dev/null 2>&1 || {
@@ -314,7 +314,7 @@ require_command() {
}
}
-require_release_dependencies() {
+function require_release_dependencies() {
require_command date
require_command git
require_command grep
@@ -322,7 +322,7 @@ require_release_dependencies() {
require_command tar
}
-validate_version() {
+function validate_version() {
local version="$1"
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
@@ -331,7 +331,7 @@ validate_version() {
fi
}
-require_project_files() {
+function require_project_files() {
local file
for file in "$MAIN_SCRIPT" "$MAN_PAGE" "$README_FILE"; do
@@ -342,7 +342,7 @@ require_project_files() {
done
}
-require_clean_worktree() {
+function require_clean_worktree() {
if ! git diff --quiet --; then
error "working tree has unstaged changes"
exit $EXIT_RUNTIME_FAILURE
@@ -354,7 +354,7 @@ require_clean_worktree() {
fi
}
-require_tag_absent() {
+function require_tag_absent() {
local version="$1"
if git rev-parse -q --verify "refs/tags/v$version" >/dev/null; then
@@ -365,7 +365,7 @@ require_tag_absent() {
# Replace a literal release metadata pattern in a file.
# Keep all sed -i portability handling in this one function.
-replace_literal() {
+function replace_literal() {
local file="$1"
local pattern="$2"
local replacement="$3"
@@ -401,7 +401,7 @@ replace_literal() {
fi
}
-update_version_and_date() {
+function update_version_and_date() {
local version="$1"
local revision_date="$2"
@@ -441,7 +441,7 @@ update_version_and_date() {
fi
}
-verify_release_metadata() {
+function verify_release_metadata() {
local version="$1"
local revision_date="$2"
@@ -478,16 +478,16 @@ verify_release_metadata() {
}
}
-read_revision_date() {
+function read_revision_date() {
sed -n -E 's/^readonly DATE_OF_REVISION=([0-9]{4}-[0-9]{2}-[0-9]{2})$/\1/p' "$MAIN_SCRIPT"
}
-show_release_diff() {
+function show_release_diff() {
msg "Release metadata diff:"
git diff -- "$MAIN_SCRIPT" "$MAN_PAGE" "$README_FILE"
}
-commit_release() {
+function commit_release() {
local version="$1"
if [[ $DRY_RUN -eq 1 ]]; then
@@ -500,7 +500,7 @@ commit_release() {
git commit -m "chore(release): prepare $version"
}
-tag_release() {
+function tag_release() {
local version="$1"
if [[ $DRY_RUN -eq 1 ]]; then
@@ -512,7 +512,7 @@ tag_release() {
git tag -a "v$version" -m "Release v$version"
}
-create_archive() {
+function create_archive() {
local version="$1"
local archive_name="$PROJECT_NAME-$version.tar.gz"
local archive_path="$DIST_DIR/$archive_name"
@@ -539,7 +539,7 @@ create_archive() {
fi
}
-prepare_release() {
+function prepare_release() {
local version="$1"
local revision_date
revision_date="$(date +%F)"
@@ -557,7 +557,7 @@ prepare_release() {
show_release_diff
}
-release() {
+function release() {
local version="$1"
local revision_date
diff --git a/transcode.sh b/transcode.sh
index b7d19ae..3137d64 100755
--- a/transcode.sh
+++ b/transcode.sh
@@ -220,7 +220,7 @@ readonly EXIT_OK EXIT_RUNTIME_FAILURE EXIT_USAGE_ERROR EXIT_CONFIG_ERROR EXIT_MI
# OUTPUT HELPERS
###############################################################################
-emit() {
+function emit() {
local prefix="$1"
local color="$2"
shift 2
@@ -246,29 +246,29 @@ emit() {
printf "\n"
}
-error() {
+function error() {
emit "==> ERROR:" "$RED" "$@" >&2
}
-msg() {
+function msg() {
if [[ $QUIET -eq 0 ]]; then
emit "==>" "$GREEN" "$@"
fi
}
-warn() {
+function warn() {
if [[ $QUIET -eq 0 ]]; then
emit "==>" "$YELLOW" "$@"
fi
}
-verbose() {
+function verbose() {
if [[ $VERBOSE -eq 1 && $QUIET -eq 0 ]]; then
emit "==>" "$BLUE" "$@"
fi
}
-debug() {
+function debug() {
if [[ $DEBUG -eq 1 ]]; then
emit "==> DEBUG:" "$MAGENTA" "$@"
fi
@@ -278,7 +278,7 @@ debug() {
# HELP AND VERSION OUTPUT
###############################################################################
-print_help() {
+function print_help() {
printf "${BOLD}${MAGENTA}%s${ALL_OFF} - ${BOLD}${CYAN}%s${ALL_OFF} - ${BOLD}%s${ALL_OFF}
${BOLD}${BLUE}Usage:${ALL_OFF} ${BOLD}${MAGENTA}%s${ALL_OFF} ${BOLD}${YELLOW}[OPTION]... [--]${ALL_OFF} ${BOLD}${GREEN}FILE...${ALL_OFF}
@@ -363,7 +363,7 @@ ${BOLD}${BLUE}Examples:${ALL_OFF}
"$SCRIPTNAME"
}
-print_version() {
+function print_version() {
printf "${RED}${BOLD}Scriptname:${ALL_OFF} %s
${GREEN}${BOLD}Version:${ALL_OFF} %s
${YELLOW}${BOLD}Description:${ALL_OFF} %s
@@ -408,25 +408,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" \
# Return the size of a file in bytes.
# Uses GNU stat -c on Linux with a fallback to BSD/macOS stat -f.
-filesize() {
+function filesize() {
stat -c "%s" -- "$1" 2>/dev/null || stat -f "%z" -- "$1"
}
# Resolve a symlink (or plain path) to its canonical absolute path.
# Uses readlink -f (GNU) with a fallback to realpath for macOS/BSD.
-resolve_path() {
+function resolve_path() {
readlink -f -- "$1" 2>/dev/null || realpath -- "$1"
}
# Format a byte count into a human-readable IEC size.
# Uses numfmt so values are displayed with binary units such as K, M, G, etc.
-format_filesize() {
+function format_filesize() {
numfmt --to=iec -- "$1"
}
# Return PATH without a leading slash so it can safely be placed below another
# directory while still preserving its absolute path structure.
-strip_leading_slash() {
+function strip_leading_slash() {
local path="$1"
path="${path#/}"
printf '%s\n' "$path"
@@ -444,7 +444,7 @@ strip_leading_slash() {
# disabled. If FORCE_COLOR is set, colors are always enabled.
###############################################################################
-setup_colors() {
+function setup_colors() {
if [[ "$ENABLE_COLOR" -eq 1 ]]; then
if tput setaf 0 >/dev/null 2>&1; then
debug "Setting colors via tput"
@@ -493,13 +493,13 @@ setup_colors() {
# Usage: _tomlq_get <key> (e.g. ".encoding.preset")
# Outputs the raw string on stdout; returns non-zero if the key is absent or
# tomlq fails for any reason.
-_tomlq_get() {
+function _tomlq_get() {
tomlq -r "$1" "$CONFIG_FILE" 2>/dev/null
}
# Load configuration from config.toml, respecting CLI precedence.
# Called once, after option parsing, so all _CLI_* sentinels are already set.
-load_config() {
+function load_config() {
# Warn about the legacy skip.conf here (not at startup) so --quiet is
# respected; by this point the CLI has been fully parsed.
if [[ -f "$SKIP_CODECS_FILE" ]]; then
@@ -704,7 +704,7 @@ load_config() {
# - Normalizes to lowercase
# - Ignores empty tokens
# - Used both for CLI --skip-codec and for codecs defined
-add_skip_codec_token() {
+function add_skip_codec_token() {
local token="${1,,}" # lowercase
if [[ ! -v SKIP_CODECS["$token"] ]]; then
debug "Add to skip codec:" "$token"
@@ -716,7 +716,7 @@ add_skip_codec_token() {
# Parse a user-provided codec list (comma/space/colon separated)
# and add each token to SKIP_CODECS
-parse_skip_codec_parameter() {
+function parse_skip_codec_parameter() {
local arg="$1"
local IFS=',: ' token
for token in $arg; do
@@ -730,7 +730,7 @@ parse_skip_codec_parameter() {
# STREAM SELECTOR HANDLING
###############################################################################
-validate_stream_selector() {
+function validate_stream_selector() {
local stream_selector="$1"
# Accept only simple video stream indexes for metadata probing. This is not a
@@ -760,7 +760,7 @@ validate_stream_selector() {
# Presets may reference variables from the caller (encode_one) such as:
# output_pixel_format, input_pixel_format, input_codec, input_frame_rate,
# input_fps, output_gop_size
-load_preset() {
+function load_preset() {
local preset_name="$1"
# Strict allowlist: only alphanumerics, hyphens, and underscores are
@@ -824,7 +824,7 @@ load_preset() {
# entry already carries it).
# - A symlink pointing outside PRESET_DIR is followed and treated as a
# regular preset file (description is read from its content).
-list_presets() {
+function list_presets() {
if [[ ! -d "$PRESET_DIR" ]]; then
warn "Preset directory does not exist:" "$PRESET_DIR"
return $EXIT_OK
@@ -883,7 +883,7 @@ list_presets() {
# Remove temporary output files created during encoding.
# Registered via trap EXIT so it runs on normal exit and on failures
# shellcheck disable=SC2329
-cleanup() {
+function cleanup() {
# "${TMP_FILES[@]+"${TMP_FILES[@]}"}" expands to nothing when the array is
# empty (safe under nounset), unlike [@]:-} which yields one empty iteration.
for t in "${TEMPORARY_FILES[@]+"${TEMPORARY_FILES[@]}"}"; do
@@ -899,7 +899,7 @@ cleanup() {
###############################################################################
# Calculate integer percentage saved from original/new byte counts.
-calculate_saved_percentage() {
+function calculate_saved_percentage() {
local original_bytes="$1"
local new_bytes="$2"
@@ -913,7 +913,7 @@ calculate_saved_percentage() {
# Append one row to the size report TSV, creating the header when needed.
# Empty byte/percentage fields are allowed for failures where no output size
# exists.
-append_size_report_row() {
+function append_size_report_row() {
if [[ $SIZE_REPORT -ne 1 || $DRY_RUN -ne 0 ]]; then
return $EXIT_OK
fi
@@ -937,7 +937,7 @@ append_size_report_row() {
# Print per-file size feedback after an encode attempt that produced an output
# file.
-print_size_report_feedback() {
+function print_size_report_feedback() {
if [[ $SIZE_REPORT -eq 0 ]]; then
return $EXIT_OK
fi
@@ -959,7 +959,7 @@ print_size_report_feedback() {
}
# Print the end-of-run size report summary for batch runs.
-print_size_report_summary() {
+function print_size_report_summary() {
local amount_total_files="$1"
if [[ $SIZE_REPORT -ne 1 || $QUIET -ne 0 || $amount_total_files -le 1 ]]; then
@@ -989,7 +989,7 @@ print_size_report_summary() {
# Return an unused backup path. Existing backups are never overwritten; numeric
# suffixes are appended until a free name is found.
-unique_backup_path() {
+function unique_backup_path() {
local target="$1"
if [[ ! -e "$target" ]]; then
@@ -1012,7 +1012,7 @@ unique_backup_path() {
# Copy the original file to BACKUP_DIR, preserving the absolute source path
# below that directory, then move the encoded temporary output into the original
# location. The original remains in place until the final replacement step.
-backup_then_replace_original() {
+function backup_then_replace_original() {
local input_file="$1"
local temporary_output_file="$2"
@@ -1062,7 +1062,7 @@ backup_then_replace_original() {
# Replace the original with the encoded output. If BACKUP_DIR is set, preserve
# the original instead of deleting it.
-replace_original() {
+function replace_original() {
local input_file="$1"
local temporary_output_file="$2"
@@ -1086,7 +1086,7 @@ replace_original() {
# Print metadata collected earlier in encode_one().
# Intentionally reads encode_one() locals via Bash dynamic scoping.
-encode_one_print_metadata() {
+function encode_one_print_metadata() {
verbose "Video stream:" "$VIDEO_STREAM"
verbose "Input codec:" "$input_codec"
verbose "Input pixel format:" "$input_pixel_format"
@@ -1114,7 +1114,7 @@ encode_one_print_metadata() {
#
# Return:
# EXIT_OK on success or if skipped; EXIT_RUNTIME_FAILURE on failure.
-encode_one() {
+function encode_one() {
local input_file="$1"
local current_file_index="$2"
local amount_total_files="$3"
diff --git a/transcode.sh.bash-completion.sh b/transcode.sh.bash-completion.sh
index 8796373..2ae59d0 100644
--- a/transcode.sh.bash-completion.sh
+++ b/transcode.sh.bash-completion.sh
@@ -13,7 +13,7 @@
# long space --encode-file list.txt
# long equals --encode-file=list.txt
-_transcode_sh() {
+function _transcode_sh() {
local cur prev
_init_completion -n = || return
@@ -22,7 +22,7 @@ _transcode_sh() {
# ---------------------------------------------------------------------------
# Helper: collect preset names from the preset directory
# ---------------------------------------------------------------------------
- _transcode_presets() {
+ function _transcode_presets() {
local presets=()
if [[ -d "$preset_dir" ]]; then
local f