something nice to have on the GNU/Linux CLI …
when using <TAB>, bash completes it if any file matches the first chars I already typed.
but what if I'm typing stuff like, il-est-midi-01.m4a, and I next need to type il-est-midi-02.m4a, etc, etc?
it will stop at il-est-midi-0, and after I type the next available digit, hitting <TAB> will not complete the file name in the onlymost reasonable way.
chatgpt suggested I would try this one:
_seqext_complete()
{
local cur=$2 dir base stem f name tail ext candidate
local had_nullglob=0
local -A seen=()
COMPREPLY=()
dir=${cur%/*}
[[ $cur == */* ]] && dir+="/" || dir="./"
base=${cur##*/}
# The current word must end in a number.
[[ $base =~ ^(.*[^0-9])([0-9]+)$ ]] || return 0
stem=${BASH_REMATCH[1]}
shopt -q nullglob && had_nullglob=1
shopt -s nullglob
for f in "$dir"*; do
[[ -f $f ]] || continue
name=${f##*/}
[[ $name == "$stem"* ]] || continue
tail=${name#"$stem"}
[[ $tail =~ ^[0-9]+(\..+)$ ]] || continue
ext=${BASH_REMATCH[1]}
candidate="$cur$ext"
if [[ -z ${seen[$candidate]+x} ]]; then
COMPREPLY+=( "$candidate" )
seen["$candidate"]=1
fi
done
(( had_nullglob )) || shopt -u nullglob
}