diff options
| author | Dennis Fink | 2026-05-22 19:37:03 +0200 |
|---|---|---|
| committer | Dennis Fink | 2026-05-22 19:37:03 +0200 |
| commit | b06aac7607cabd5b192cc37b357c75e933f6ed13 (patch) | |
| tree | e0e7ff82671a6a7df41bbfeddcd9fb978711e815 /transcode.sh.bash-completion.sh | |
| parent | dad27b5f2ce5fb5b907bf3c552164d032d5048fd (diff) | |
| download | transcode.sh-b06aac7607cabd5b192cc37b357c75e933f6ed13.tar.gz transcode.sh-b06aac7607cabd5b192cc37b357c75e933f6ed13.zip | |
chore(completion): add shell extension to completion file
Rename the bash completion script to use a .sh extension so its file
type is clearer in editors and tooling.
Keep the completion contents unchanged while making the filename
consistent with the script-style files in the repository.
Diffstat (limited to 'transcode.sh.bash-completion.sh')
| -rw-r--r-- | transcode.sh.bash-completion.sh | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/transcode.sh.bash-completion.sh b/transcode.sh.bash-completion.sh new file mode 100644 index 0000000..c980081 --- /dev/null +++ b/transcode.sh.bash-completion.sh @@ -0,0 +1,219 @@ +# SPDX-FileCopyrightText: 2025 Dennis Fink <me+coding@dennisfink.me> +# +# SPDX-License-Identifier: BSD-3-Clause + +# bash completion for transcode.sh +# Install to: +# /etc/bash_completion.d/transcode.sh +# or source manually: +# source transcode.sh.bash-completion +# +# Each option that takes an argument is supported in all three forms: +# short -f list.txt +# long space --encode-file list.txt +# long equals --encode-file=list.txt + +_transcode_sh() { + local cur prev words cword + _init_completion || return + + local -r preset_dir="${XDG_CONFIG_HOME:-$HOME/.config}/transcode.sh/presets" + + # --------------------------------------------------------------------------- + # Helper: collect preset names from the preset directory + # --------------------------------------------------------------------------- + _transcode_presets() { + local presets=() + if [[ -d "$preset_dir" ]]; then + local f + while IFS= read -r f; do + f="${f##*/}" # basename + f="${f%.sh}" # strip .sh extension + presets+=("$f") + done < <(find "$preset_dir" -maxdepth 1 -name '*.sh' -type f 2>/dev/null) + fi + printf '%s\n' "${presets[@]}" + } + + local codecs='h264 hevc av1 vp8 vp9 mpeg2video mpeg4 mjpeg theora' + local nice_vals='0 5 10 15 19' + local hwaccel_methods='auto cuda vaapi dxva2 d3d11va videotoolbox qsv' + local ffmpeg_loglevels='quiet panic fatal error warning info verbose debug trace' + local video_streams='v:0 v:1 v:2 v:3' + + # --------------------------------------------------------------------------- + # Handle --option=VALUE: cur contains the entire "--opt=val" token. + # Strip the "opt=" prefix and delegate to the appropriate completer. + # This must be checked before the $prev dispatch below. + # --------------------------------------------------------------------------- + case "$cur" in + --config-file=*) + cur="${cur#*=}" + _filedir + return + ;; + --backup-dir=*) + cur="${cur#*=}" + _filedir -d + return + ;; + --encode-file=*) + cur="${cur#*=}" + _filedir + return + ;; + --size-report-file=*) + cur="${cur#*=}" + _filedir + return + ;; + --nice=*) + cur="${cur#*=}" + COMPREPLY=($(compgen -W "$nice_vals" -- "$cur")) + return + ;; + --skip-codec=*) + cur="${cur#*=}" + COMPREPLY=($(compgen -W "$codecs" -- "$cur")) + return + ;; + --preset=*) + cur="${cur#*=}" + COMPREPLY=($(compgen -W "$(_transcode_presets)" -- "$cur")) + return + ;; + --hwaccel=*) + cur="${cur#*=}" + COMPREPLY=($(compgen -W "$hwaccel_methods" -- "$cur")) + return + ;; + --ffmpeg-loglevel=*) + cur="${cur#*=}" + COMPREPLY=($(compgen -W "$ffmpeg_loglevels" -- "$cur")) + return + ;; + --video-stream=*) + cur="${cur#*=}" + COMPREPLY=($(compgen -W "$video_streams" -- "$cur")) + return + ;; + esac + + # --------------------------------------------------------------------------- + # Handle VALUE after short form (-f, -N, -S, -p) and + # long space form (--encode-file, --nice, --size-report-file, --skip-codec, --preset). + # $prev is the option word, $cur is the value being typed. + # --------------------------------------------------------------------------- + case "$prev" in + --config-file) + _filedir + return + ;; + --backup-dir) + _filedir -d + return + ;; + -f | --encode-file) + _filedir + return + ;; + -N | --nice) + COMPREPLY=($(compgen -W "$nice_vals" -- "$cur")) + return + ;; + --size-report-file) + _filedir + return + ;; + -S | --skip-codec) + COMPREPLY=($(compgen -W "$codecs" -- "$cur")) + return + ;; + -p | --preset) + COMPREPLY=($(compgen -W "$(_transcode_presets)" -- "$cur")) + return + ;; + --hwaccel) + COMPREPLY=($(compgen -W "$hwaccel_methods" -- "$cur")) + return + ;; + --ffmpeg-loglevel) + COMPREPLY=($(compgen -W "$ffmpeg_loglevels" -- "$cur")) + return + ;; + --video-stream) + COMPREPLY=($(compgen -W "$video_streams" -- "$cur")) + return + ;; + esac + + # --------------------------------------------------------------------------- + # Complete option names themselves. + # For options that accept an argument we list both the bare long form + # (--nice) and the equals form (--nice=) so the user can choose their + # preferred style. compopt -o nospace is applied when the sole match + # ends with '=' to avoid an unwanted trailing space in that case. + # --------------------------------------------------------------------------- + case "$cur" in + --*) + local longopts=' + --backup-dir + --backup-dir= + --color + --config-file + --config-file= + --continue + --dry-run + --encode-file + --encode-file= + --ffmpeg-loglevel + --ffmpeg-loglevel= + --help + --hwaccel + --hwaccel= + --list-presets + --nice + --nice= + --no-color + --no-continue + --no-hwaccel + --no-only-if-smaller + --no-size-report + --no-verify-output + --only-if-smaller + --preset + --preset= + --quiet + --size-report + --size-report-file + --size-report-file= + --skip-codec + --skip-codec-override + --skip-codec= + --verbose + --verify-output + --version + --video-stream + --video-stream= + ' + COMPREPLY=($(compgen -W "$longopts" -- "$cur")) + # Suppress the trailing space when the only completion ends with '=' + [[ ${#COMPREPLY[@]} -eq 1 && "${COMPREPLY[0]}" == *= ]] && + compopt -o nospace + return + ;; + -*) + local shortopts='-c -f -n -N -s -S -l -p -h -? -q -v --' + COMPREPLY=($(compgen -W "$shortopts" -- "$cur")) + return + ;; + esac + + # --------------------------------------------------------------------------- + # Default: complete positional FILE arguments with common media extensions + # --------------------------------------------------------------------------- + _filedir '@(mkv|mp4|mov|avi|webm|flv|wmv|m4v|ts|mts|m2ts|mpg|mpeg|ogv|3gp|rm|rmvb)' +} + +complete -F _transcode_sh transcode.sh +complete -F _transcode_sh transcode |
