[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1bfaacd1a0a79b26b682ed8676341ee88f4ee92d
Guillaume Rousse
guillomovitch at zarb.org
Wed May 20 23:42:45 UTC 2009
The following commit has been merged in the master branch:
commit f60e97d0c2ad6d82575d07473543eced6072f67d
Author: Guillaume Rousse <guillomovitch at zarb.org>
Date: Thu May 21 01:38:13 2009 +0200
split tar completion
diff --git a/Makefile.am b/Makefile.am
index 3a280b4..549a787 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -82,6 +82,7 @@ bashcomp_DATA = contrib/ant \
contrib/strace \
contrib/_subversion \
contrib/svk \
+ contrib/tar \
contrib/unace \
contrib/unrar \
contrib/vncviewer \
diff --git a/bash_completion b/bash_completion
index 320e632..eeeb31a 100644
--- a/bash_completion
+++ b/bash_completion
@@ -2892,70 +2892,6 @@ _route()
}
[ $UNAME = Linux ] && complete -F _route route
-# GNU tar(1) completion
-#
-_tar()
-{
- local cur ext regex tar untar
-
- COMPREPLY=()
- cur=`_get_cword`
-
- if [ $COMP_CWORD -eq 1 ]; then
- COMPREPLY=( $( compgen -W 'c t x u r d A' -- $cur ) )
- return 0
- fi
-
- case "${COMP_WORDS[1]}" in
- ?(-)[cr]*f)
- _filedir
- return 0
- ;;
- +([^IZzJjy])f)
- ext='t@(ar?(.@(Z|gz|bz?(2)|lz?(ma)))|gz|bz?(2)|lz?(ma))'
- regex='t\(ar\(\.\(Z\|gz\|bz2\?\|lzma\|xz\)\)\?\|gz\|bz2\?\|lzma\|xz\)'
- ;;
- *[Zz]*f)
- ext='t?(ar.)@(gz|Z)'
- regex='t\(ar\.\)\?\(gz\|Z\)'
- ;;
- *[Ijy]*f)
- ext='t?(ar.)bz?(2)'
- regex='t\(ar\.\)\?bz2\?'
- ;;
- *[J]*f)
- ext='t?(ar.)@(lz?(ma)|xz)'
- regex='t\(ar\.\)\?\(lzma\|xz\)\?'
- ;;
- *)
- _filedir
- return 0
- ;;
-
- esac
-
- if [[ "$COMP_LINE" == *$ext' ' ]]; 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${COMP_WORDS[1]//[^Izjyf]/}
-
- COMPREPLY=( $( compgen -W "$( echo $( tar $untar $tar \
- 2>/dev/null ) )" -- "$cur" ) )
- return 0
- fi
-
- # file completion on relevant files
- _filedir "$ext"
-
- return 0
-}
-[ -n "${COMP_TAR_INTERNAL_PATHS:-}" ] && complete -F _tar $dirnames tar ||
- complete -F _tar $filenames tar
-
# jar(1) completion
#
have jar &&
diff --git a/contrib/tar b/contrib/tar
new file mode 100644
index 0000000..dadd788
--- /dev/null
+++ b/contrib/tar
@@ -0,0 +1,66 @@
+# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
+# ex: ts=8 sw=8 noet filetype=sh
+#
+# bash completion for GNU tar
+
+_tar()
+{
+ local cur ext regex tar untar
+
+ COMPREPLY=()
+ cur=`_get_cword`
+
+ if [ $COMP_CWORD -eq 1 ]; then
+ COMPREPLY=( $( compgen -W 'c t x u r d A' -- $cur ) )
+ return 0
+ fi
+
+ case "${COMP_WORDS[1]}" in
+ ?(-)[cr]*f)
+ _filedir
+ return 0
+ ;;
+ +([^IZzJjy])f)
+ ext='t@(ar?(.@(Z|gz|bz?(2)|lz?(ma)))|gz|bz?(2)|lz?(ma))'
+ regex='t\(ar\(\.\(Z\|gz\|bz2\?\|lzma\|xz\)\)\?\|gz\|bz2\?\|lzma\|xz\)'
+ ;;
+ *[Zz]*f)
+ ext='t?(ar.)@(gz|Z)'
+ regex='t\(ar\.\)\?\(gz\|Z\)'
+ ;;
+ *[Ijy]*f)
+ ext='t?(ar.)bz?(2)'
+ regex='t\(ar\.\)\?bz2\?'
+ ;;
+ *[J]*f)
+ ext='t?(ar.)@(lz?(ma)|xz)'
+ regex='t\(ar\.\)\?\(lzma\|xz\)\?'
+ ;;
+ *)
+ _filedir
+ return 0
+ ;;
+
+ esac
+
+ if [[ "$COMP_LINE" == *$ext' ' ]]; 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${COMP_WORDS[1]//[^Izjyf]/}
+
+ COMPREPLY=( $( compgen -W "$( echo $( tar $untar $tar \
+ 2>/dev/null ) )" -- "$cur" ) )
+ return 0
+ fi
+
+ # file completion on relevant files
+ _filedir "$ext"
+
+ return 0
+}
+[ -n "${COMP_TAR_INTERNAL_PATHS:-}" ] && complete -F _tar $dirnames tar ||
+ complete -F _tar $filenames tar
--
bash-completion
More information about the Bash-completion-commits
mailing list