home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / bash_completion.d / tar < prev    next >
Encoding:
Text File  |  2010-11-16  |  1.6 KB  |  73 lines

  1. # bash completion for GNU tar
  2.  
  3. have tar && {
  4. _tar()
  5. {
  6.     local cur ext regex tar untar
  7.  
  8.     COMPREPLY=()
  9.     _get_comp_words_by_ref cur
  10.  
  11.     if [ $COMP_CWORD -eq 1 ]; then
  12.         COMPREPLY=( $( compgen -W 'c t x u r d A' -- "$cur" ) )
  13.         return 0
  14.     fi
  15.  
  16.     case ${COMP_WORDS[1]} in
  17.     ?(-)[cr]*f)
  18.         _filedir
  19.         return 0
  20.         ;;
  21.     +([^IZzJjy])f)
  22.         ext='t@(ar?(.@(Z|gz|bz?(2)|lz?(ma)|xz))|gz|bz?(2)|lz?(ma)|xz)'
  23.         regex='t\(ar\(\.\(Z\|gz\|bz2\?\|lzma\|xz\)\)\?\|gz\|bz2\?\|lzma\|xz\)'
  24.         ;;
  25.     *[Zz]*f)
  26.         ext='t?(ar.)@(gz|Z)'
  27.         regex='t\(ar\.\)\?\(gz\|Z\)'
  28.         ;;
  29.     *[Ijy]*f)
  30.         ext='t?(ar.)bz?(2)'
  31.         regex='t\(ar\.\)\?bz2\?'
  32.         ;;
  33.     *[J]*f)
  34.         ext='t?(ar.)@(lz?(ma)|xz)'
  35.         regex='t\(ar\.\)\?\(lzma\|xz\)\?'
  36.         ;;
  37.     *)
  38.         _filedir
  39.         return 0
  40.         ;;
  41.  
  42.     esac
  43.  
  44.     if [[ "$COMP_LINE" == *$ext' ' ]]; then
  45.         # complete on files in tar file
  46.         #
  47.         # get name of tar file from command line
  48.         tar=$( sed -e 's/^.* \([^ ]*'$regex'\) .*$/\1/' <<<"$COMP_LINE" )
  49.         # devise how to untar and list it
  50.         untar=t${COMP_WORDS[1]//[^Izjyf]/}
  51.  
  52.         COMPREPLY=( $( compgen -W "$( printf '%s ' $( tar $untar $tar \
  53.             2>/dev/null ) )" -- "$cur" ) )
  54.         return 0
  55.     fi
  56.  
  57.     # file completion on relevant files
  58.     _filedir "$ext"
  59.  
  60.     return 0
  61. }
  62. [ -n "${COMP_TAR_INTERNAL_PATHS:-}" ] && complete -F _tar -o dirnames tar ||
  63.     complete -F _tar -o filenames tar
  64. }
  65.  
  66. # Local variables:
  67. # mode: shell-script
  68. # sh-basic-offset: 4
  69. # sh-indent-comment: t
  70. # indent-tabs-mode: nil
  71. # End:
  72. # ex: ts=4 sw=4 et filetype=sh
  73.