bash : archive_rename : add autocompletion.

This commit is contained in:
Dmitry Voronin 2023-10-29 22:04:26 +03:00
parent 40774fd82e
commit 523404ecb3
2 changed files with 28 additions and 12 deletions

View file

@ -178,4 +178,23 @@ _archive_list()
_autocomplete "$(ls *_*.tar.* 2> /dev/null)" _autocomplete "$(ls *_*.tar.* 2> /dev/null)"
} }
_archive_rename()
{
COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
local command="${COMP_WORDS[0]}"
if [[ "${prev}" = "${command}" ]]; then
COMPREPLY=( $(compgen -W "$(ls -a)" -- ${cur}) )
return 0
else
local name="${prev%_*}"
COMPREPLY=( $(compgen -W "${name}" -- ${cur}) )
return 0
fi
}
complete -o plusdirs -F _archive_list archive_check unarchive complete -o plusdirs -F _archive_list archive_check unarchive
complete -F _archive_rename archive_rename

View file

@ -4,13 +4,12 @@
_autocomplete() _autocomplete()
{ {
local commands="$@" local commands="$@"
local cur prev
COMPREPLY=() COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}" local cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" local prev="${COMP_WORDS[COMP_CWORD-1]}"
command="${COMP_WORDS[0]}" local command="${COMP_WORDS[0]}"
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
return 0 return 0
@ -20,13 +19,12 @@ _autocomplete()
_autocomplete_first() _autocomplete_first()
{ {
local commands="$@" local commands="$@"
local cur prev
COMPREPLY=() COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}" local cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" local prev="${COMP_WORDS[COMP_CWORD-1]}"
command="${COMP_WORDS[0]}" local command="${COMP_WORDS[0]}"
if [[ "${prev}" = "${command}" ]]; then if [[ "${prev}" = "${command}" ]]; then
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
@ -38,13 +36,12 @@ _autocomplete_first()
_autocomplete_first_ls() _autocomplete_first_ls()
{ {
local commands="$@" local commands="$@"
local cur prev
COMPREPLY=() COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}" local cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" local prev="${COMP_WORDS[COMP_CWORD-1]}"
command="${COMP_WORDS[0]}" local command="${COMP_WORDS[0]}"
if [[ "${prev}" = "${command}" ]]; then if [[ "${prev}" = "${command}" ]]; then
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )