- tar completion now completes first on tar files, then on their contents
This commit is contained in:
parent
ae76dc287a
commit
835bc25be6
@ -1,6 +1,6 @@
|
|||||||
# bash_completion - some programmable completion functions for bash 2.05a
|
# bash_completion - some programmable completion functions for bash 2.05a
|
||||||
#
|
#
|
||||||
# $Id: bash_completion,v 1.342 2002/06/01 21:16:20 ianmacd Exp $
|
# $Id: bash_completion,v 1.343 2002/06/02 22:19:38 ianmacd Exp $
|
||||||
#
|
#
|
||||||
# Copyright (C) Ian Macdonald <ian@caliban.org>
|
# Copyright (C) Ian Macdonald <ian@caliban.org>
|
||||||
#
|
#
|
||||||
@ -24,9 +24,8 @@
|
|||||||
|
|
||||||
# Alter the following to reflect the location of this file
|
# Alter the following to reflect the location of this file
|
||||||
#
|
#
|
||||||
[ -z "$BASH_COMPLETION" ] && declare -r BASH_COMPLETION=/etc/bash_completion
|
declare -r BASH_COMPLETION=${BASH_COMPLETION:-/etc/bash_completion}
|
||||||
[ -z "$BASH_COMPLETION_DIR" ] && \
|
declare -r BASH_COMPLETION_DIR=${BASH_COMPLETION_DIR:=/etc/bash_completion}
|
||||||
declare -r BASH_COMPLETION_DIR=/etc/bash_completion.d
|
|
||||||
|
|
||||||
# Set a couple of useful vars
|
# Set a couple of useful vars
|
||||||
#
|
#
|
||||||
@ -1903,7 +1902,7 @@ _service()
|
|||||||
#
|
#
|
||||||
_tar()
|
_tar()
|
||||||
{
|
{
|
||||||
local cur
|
local cur ext regex tar untar
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
@ -1916,22 +1915,44 @@ _tar()
|
|||||||
case "${COMP_WORDS[1]}" in
|
case "${COMP_WORDS[1]}" in
|
||||||
c*f)
|
c*f)
|
||||||
_filedir
|
_filedir
|
||||||
|
return 0
|
||||||
;;
|
;;
|
||||||
+([^Izjy])f)
|
+([^Izjy])f)
|
||||||
_filedir 'tar'
|
ext='tar'
|
||||||
|
regex=$ext
|
||||||
;;
|
;;
|
||||||
*z*f)
|
*z*f)
|
||||||
_filedir 't?(ar.)gz'
|
ext='t?(ar.)gz'
|
||||||
|
regex='t\(ar\.\)gz'
|
||||||
;;
|
;;
|
||||||
*[Ijy]*f)
|
*[Ijy]*f)
|
||||||
_filedir 'tar.bz2'
|
ext='tar.bz2'
|
||||||
|
regex='tar\.bz2'
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
_filedir
|
_filedir
|
||||||
|
return 0
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
if [ "${COMP_LINE#*$ext }" != "$COMP_LINE" ]; then
|
||||||
|
# complete on files in tar file
|
||||||
|
#
|
||||||
|
# get name of tar file from command line
|
||||||
|
tar=$( echo "$COMP_LINE" | \
|
||||||
|
sed -e 's/^.* \([^ ]*'$regex'\) .*$/\1/' )
|
||||||
|
# devise how to untar and list it
|
||||||
|
untar=t$( echo ${COMP_WORDS[1]} | tr -cd Izjyf )
|
||||||
|
|
||||||
|
COMPREPLY=( $( compgen -W "$( tar $untar $tar 2>/dev/null )" \
|
||||||
|
-- "$cur" ) )
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
# file completion on relevant files
|
||||||
|
_filedir $ext
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
complete -F _tar $filenames tar
|
complete -F _tar $filenames tar
|
||||||
|
Loading…
x
Reference in New Issue
Block a user