bash : archive : improve completion.
This commit is contained in:
parent
91d522a551
commit
25e8685790
|
@ -322,6 +322,7 @@ Command|Description
|
|||
---|---
|
||||
`_autocomplete <ARGS>`|Provide completion based on provided arguments separated by spaces.
|
||||
`_autocomplete_first <ARGS>`|Same as `_autocomplete` but works only once for first argument.
|
||||
`_autocomplete_grep <PATTERN>`|Ls autocomplete with specified grep filter.
|
||||
`_autocomplete_nested`|Provides nested completions, just like `sudo` does.
|
||||
|
||||
## Battery.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
_ARCHIVE_PATTERN="_[[:alnum:]]{40}.tar.[xg]z"
|
||||
|
||||
# archive file with maximum compression and checksum.
|
||||
# usage: archive [FILES]
|
||||
archive()
|
||||
|
@ -71,7 +73,7 @@ archive_check()
|
|||
|
||||
# set dafult value to target all supported archives.
|
||||
if [[ "${targets}" = "" ]]; then
|
||||
targets=(*_*.tar.*)
|
||||
targets=(${_ARCHIVE_PATTERN})
|
||||
total=${#targets[@]}
|
||||
fi
|
||||
|
||||
|
@ -122,7 +124,7 @@ unarchive()
|
|||
|
||||
# set dafult value to target all supported archives.
|
||||
if [[ "${targets}" = "" ]]; then
|
||||
targets=(*_*.tar.*)
|
||||
targets=(${_ARCHIVE_PATTERN})
|
||||
total=${#targets[@]}
|
||||
fi
|
||||
|
||||
|
@ -162,7 +164,7 @@ archive_name()
|
|||
|
||||
# set dafult value to target all supported archives.
|
||||
if [[ "${targets}" = "" ]]; then
|
||||
targets=(*_*.tar.*)
|
||||
targets=(${_ARCHIVE_PATTERN})
|
||||
total=${#targets[@]}
|
||||
fi
|
||||
|
||||
|
@ -217,7 +219,7 @@ _archive_name()
|
|||
local command="${COMP_WORDS[0]}"
|
||||
|
||||
if [[ "${prev}" = "${command}" ]]; then
|
||||
COMPREPLY=( $(compgen -W "$(ls *_*.tar.*)" -- ${cur}) )
|
||||
COMPREPLY=( $(compgen -W "$(ls | grep -E ${_ARCHIVE_PATTERN})" -- ${cur}) )
|
||||
return 0
|
||||
else
|
||||
local name="${prev%_*}"
|
||||
|
@ -226,5 +228,10 @@ _archive_name()
|
|||
fi
|
||||
}
|
||||
|
||||
complete -f -X "!*_*.tar.*" archive_check unarchive
|
||||
_archive_grep()
|
||||
{
|
||||
_autocomplete_grep ${_ARCHIVE_PATTERN}
|
||||
}
|
||||
|
||||
complete -F _archive_grep archive_check unarchive
|
||||
complete -F _archive_name archive_name
|
||||
|
|
|
@ -32,6 +32,19 @@ _autocomplete_first()
|
|||
fi
|
||||
}
|
||||
|
||||
_autocomplete_grep()
|
||||
{
|
||||
COMPREPLY=()
|
||||
|
||||
local pattern="${1}"
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
local command="${COMP_WORDS[0]}"
|
||||
|
||||
COMPREPLY=( $(compgen -W "$(ls | grep -E ${pattern})" -- ${cur}) )
|
||||
return 0
|
||||
}
|
||||
|
||||
# autocomplete nested program.
|
||||
_autocomplete_nested()
|
||||
{
|
||||
|
|
Reference in a new issue