tar: Style tweaks
parent
a8f450797b
commit
055d1ae59f
|
@ -116,7 +116,7 @@ __gnu_tar_parse_help()
|
||||||
# variable may contain e.g. '-X, --XXX[=NAME], -XXX2[=NAME]'.
|
# variable may contain e.g. '-X, --XXX[=NAME], -XXX2[=NAME]'.
|
||||||
arg=none
|
arg=none
|
||||||
if [[ "$line" =~ --[A-Za-z0-9-]+(\[?)= ]]; then
|
if [[ "$line" =~ --[A-Za-z0-9-]+(\[?)= ]]; then
|
||||||
test -n "${BASH_REMATCH[1]}" && arg=opt || arg=req
|
[[ -n "${BASH_REMATCH[1]}" ]] && arg=opt || arg=req
|
||||||
fi
|
fi
|
||||||
|
|
||||||
__gtar_parse_help_line "$str" "$arg"
|
__gtar_parse_help_line "$str" "$arg"
|
||||||
|
@ -155,19 +155,19 @@ __tar_parse_old_opt()
|
||||||
local first_word char
|
local first_word char
|
||||||
|
|
||||||
# current word is the first word
|
# current word is the first word
|
||||||
test "$cword" -eq 1 -a -n "$cur" -a "${cur:0:1}" != '-' \
|
[[ "$cword" -eq 1 && -n "$cur" && "${cur:0:1}" != '-' ]] \
|
||||||
&& old_opt_progress=1
|
&& old_opt_progress=1
|
||||||
|
|
||||||
# check that first argument does not begin with "-"
|
# check that first argument does not begin with "-"
|
||||||
first_word=${words[1]}
|
first_word=${words[1]}
|
||||||
test -n "$first_word" -a "${first_word:0:1}" != "-" \
|
[[ -n "$first_word" && "${first_word:0:1}" != "-" ]] \
|
||||||
&& old_opt_used=1
|
&& old_opt_used=1
|
||||||
|
|
||||||
# parse the old option (if present) contents to allow later code expect
|
# parse the old option (if present) contents to allow later code expect
|
||||||
# corresponding arguments
|
# corresponding arguments
|
||||||
if test $old_opt_used -eq 1; then
|
if [[ $old_opt_used -eq 1 ]]; then
|
||||||
char=${first_word:0:1}
|
char=${first_word:0:1}
|
||||||
while test -n "$char"; do
|
while [[ -n "$char" ]]; do
|
||||||
if __tar_is_argreq "$char"; then
|
if __tar_is_argreq "$char"; then
|
||||||
old_opt_parsed+=("$char")
|
old_opt_parsed+=("$char")
|
||||||
fi
|
fi
|
||||||
|
@ -206,7 +206,7 @@ __tar_preparse_cmdline()
|
||||||
;;
|
;;
|
||||||
*[$modes]*)
|
*[$modes]*)
|
||||||
# Only the first arg may be "MODE" without leading dash
|
# Only the first arg may be "MODE" without leading dash
|
||||||
if test $first_arg -eq 1; then
|
if [[ $first_arg -eq 1 ]]; then
|
||||||
tar_mode=${i//[^$modes]/}
|
tar_mode=${i//[^$modes]/}
|
||||||
tar_mode=${tar_mode:0:1}
|
tar_mode=${tar_mode:0:1}
|
||||||
tar_mode_arg=$i
|
tar_mode_arg=$i
|
||||||
|
@ -265,7 +265,7 @@ __tar_complete_mode()
|
||||||
filler i
|
filler i
|
||||||
|
|
||||||
short_modes="ctx"
|
short_modes="ctx"
|
||||||
test x"$basic_tar" = x && short_modes="ctxurdA"
|
[[ -z "$basic_tar" ]] && short_modes="ctxurdA"
|
||||||
|
|
||||||
# Remove prefix when needed
|
# Remove prefix when needed
|
||||||
rawopt=${cur#-}
|
rawopt=${cur#-}
|
||||||
|
@ -274,18 +274,18 @@ __tar_complete_mode()
|
||||||
allshort_raw=${short_opts//[- ]/}
|
allshort_raw=${short_opts//[- ]/}
|
||||||
|
|
||||||
# init the 'mode' option if no option is in ${cur}
|
# init the 'mode' option if no option is in ${cur}
|
||||||
if test "$tar_mode" = none; then
|
if [[ "$tar_mode" == none ]]; then
|
||||||
|
|
||||||
# when user passed something like 'tar cf' do not put the '-' before
|
# when user passed something like 'tar cf' do not put the '-' before
|
||||||
filler=
|
filler=
|
||||||
if test -z "$cur" && test x"$basic_tar" = x; then
|
if [[ -z "$cur" && -z "$basic_tar" ]]; then
|
||||||
filler=-
|
filler=-
|
||||||
fi
|
fi
|
||||||
|
|
||||||
generated=""
|
generated=""
|
||||||
for (( i=0 ; 1; i++ )); do
|
for (( i=0 ; 1; i++ )); do
|
||||||
local c="${short_modes:$i:1}"
|
local c="${short_modes:$i:1}"
|
||||||
test -z "$c" && break
|
[[ -z "$c" ]] && break
|
||||||
generated+=" $filler$cur$c"
|
generated+=" $filler$cur$c"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -295,20 +295,20 @@ __tar_complete_mode()
|
||||||
|
|
||||||
# The last short option requires argument, like '-cf<TAB>'. Cut the
|
# The last short option requires argument, like '-cf<TAB>'. Cut the
|
||||||
# completion here to enforce argument processing.
|
# completion here to enforce argument processing.
|
||||||
if test "$old_opt_progress" -eq 0 \
|
if [[ "$old_opt_progress" -eq 0 ]] \
|
||||||
&& __tar_is_argreq "$(__tar_last_char "$cur")"; then
|
&& __tar_is_argreq "$(__tar_last_char "$cur")"; then
|
||||||
COMPREPLY=( "$cur" ) && return 0
|
COMPREPLY=( "$cur" ) && return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
allshort_raw_unused=${allshort_raw//[$rawopt]/}
|
allshort_raw_unused=${allshort_raw//[$rawopt]/}
|
||||||
if test "$tar_mode" != none; then
|
if [[ "$tar_mode" != none ]]; then
|
||||||
allshort_raw_unused=${allshort_raw_unused//[$short_modes]}
|
allshort_raw_unused=${allshort_raw_unused//[$short_modes]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
generated=
|
generated=
|
||||||
for (( i=0 ; 1; i++ )); do
|
for (( i=0 ; 1; i++ )); do
|
||||||
local c="${allshort_raw_unused:$i:1}"
|
local c="${allshort_raw_unused:$i:1}"
|
||||||
test -z "$c" && break
|
[[ -z "$c" ]] && break
|
||||||
generated+=" $cur$c"
|
generated+=" $cur$c"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ __gtar_complete_sopts()
|
||||||
|
|
||||||
for (( i=0 ; 1; i++ )); do
|
for (( i=0 ; 1; i++ )); do
|
||||||
c="${allshort_raw_unused:$i:1}"
|
c="${allshort_raw_unused:$i:1}"
|
||||||
test -z "$c" && break
|
[[ -z "$c" ]] && break
|
||||||
generated+=" $cur$c"
|
generated+=" $cur$c"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -349,20 +349,20 @@ __tar_try_mode()
|
||||||
case "$cur" in
|
case "$cur" in
|
||||||
--*)
|
--*)
|
||||||
# posix tar does not support long opts
|
# posix tar does not support long opts
|
||||||
test -n "$basic_tar" && return 0
|
[[ -n "$basic_tar" ]] && return 0
|
||||||
__gtar_complete_lopts
|
__gtar_complete_lopts
|
||||||
return $?
|
return $?
|
||||||
;;
|
;;
|
||||||
|
|
||||||
-*)
|
-*)
|
||||||
# posix tar does not support short optios
|
# posix tar does not support short optios
|
||||||
test -n "$basic_tar" && return 0
|
[[ -n "$basic_tar" ]] && return 0
|
||||||
|
|
||||||
__tar_complete_mode && return 0
|
__tar_complete_mode && return 0
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
if test "$cword" -eq 1 || test "$tar_mode" = none; then
|
if [[ "$cword" -eq 1 || "$tar_mode" == none ]]; then
|
||||||
__tar_complete_mode && return 0
|
__tar_complete_mode && return 0
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
@ -376,9 +376,8 @@ __tar_adjust_PREV_from_old_option()
|
||||||
# deal with old style arguments here
|
# deal with old style arguments here
|
||||||
# $ tar cfTC # expects this sequence of arguments:
|
# $ tar cfTC # expects this sequence of arguments:
|
||||||
# $ tar cfTC ARCHIVE_FILE PATTERNS_FILE CHANGE_DIR
|
# $ tar cfTC ARCHIVE_FILE PATTERNS_FILE CHANGE_DIR
|
||||||
if test "$old_opt_used" -eq 1 \
|
if [[ "$old_opt_used" -eq 1 && "$cword" -gt 1 \
|
||||||
-a "$cword" -gt 1 \
|
&& "$cword" -lt $(( ${#old_opt_parsed[@]} + 2 )) ]];
|
||||||
-a "$cword" -lt $(( ${#old_opt_parsed[@]} + 2 ));
|
|
||||||
then
|
then
|
||||||
# make e.g. 'C' option from 'cffCT'
|
# make e.g. 'C' option from 'cffCT'
|
||||||
prev="-${old_opt_parsed[ $cword - 2 ]}"
|
prev="-${old_opt_parsed[ $cword - 2 ]}"
|
||||||
|
@ -390,7 +389,7 @@ __tar_extract_like_mode()
|
||||||
{
|
{
|
||||||
local i
|
local i
|
||||||
for i in x d t delete; do
|
for i in x d t delete; do
|
||||||
test "$tar_mode" = "$i" && return 0
|
[[ "$tar_mode" == "$i" ]] && return 0
|
||||||
done
|
done
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
@ -412,7 +411,7 @@ __tar_try_list_archive()
|
||||||
|
|
||||||
read tarball <<<"$(printf -- '%s\n' "$@" \
|
read tarball <<<"$(printf -- '%s\n' "$@" \
|
||||||
| sed -n "/^.\{1,\}$regex\$/p" | tee /tmp/jetel)"
|
| sed -n "/^.\{1,\}$regex\$/p" | tee /tmp/jetel)"
|
||||||
if test -n "$tarball"; then
|
if [[ -n "$tarball" ]]; then
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
COMPREPLY=($(compgen -o filenames -W "$(
|
COMPREPLY=($(compgen -o filenames -W "$(
|
||||||
while read line; do
|
while read line; do
|
||||||
|
@ -486,7 +485,7 @@ _gtar()
|
||||||
# FIXME: handle long options
|
# FIXME: handle long options
|
||||||
local tar_mode_arg=
|
local tar_mode_arg=
|
||||||
|
|
||||||
if test "$_TAR_OPT_DEBUG" = 1; then
|
if [[ "$_TAR_OPT_DEBUG" == 1 ]]; then
|
||||||
set -x
|
set -x
|
||||||
PS4="\$BASH_SOURCE:\$LINENO: "
|
PS4="\$BASH_SOURCE:\$LINENO: "
|
||||||
fi
|
fi
|
||||||
|
@ -612,19 +611,19 @@ _gtar()
|
||||||
|
|
||||||
# the first argument must be "mode" argument or --param, if any of those
|
# the first argument must be "mode" argument or --param, if any of those
|
||||||
# was truth - the 'break' statement would have been already called
|
# was truth - the 'break' statement would have been already called
|
||||||
test "$cword" -eq 1 && break
|
[[ "$cword" -eq 1 ]] && break
|
||||||
|
|
||||||
__tar_try_list_archive && break
|
__tar_try_list_archive && break
|
||||||
|
|
||||||
# file completion on relevant files
|
# file completion on relevant files
|
||||||
if test $tar_mode != none; then
|
if [[ $tar_mode != none ]]; then
|
||||||
_filedir
|
_filedir
|
||||||
fi
|
fi
|
||||||
|
|
||||||
break
|
break
|
||||||
done # just-for-easy-break while
|
done # just-for-easy-break while
|
||||||
|
|
||||||
if test "$_TAR_OPT_DEBUG" = 1; then
|
if [[ "$_TAR_OPT_DEBUG" == 1 ]]; then
|
||||||
set +x
|
set +x
|
||||||
unset PS4
|
unset PS4
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue