/bash_completion.d/xz

http://github.com/brinkman83/bashrc · #! · 103 lines · 88 code · 15 blank · 0 comment · 0 complexity · 925348ff196b3ed67eccd2c753163809 MD5 · raw file

  1. # xz(1) completion
  2. have xz &&
  3. _xz()
  4. {
  5. COMPREPLY=()
  6. local cur=`_get_cword`
  7. local prev=${COMP_WORDS[COMP_CWORD-1]}
  8. if [[ "$cur" == -* ]]; then
  9. COMPREPLY=( $( compgen -W '-z --compress -d --decompress \
  10. -t --test -l --list -k --keep -f --force -c --stdout \
  11. -S --suffix --files --files0 -F --format -C --check \
  12. -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -M --memory --lzma1 \
  13. --lzma2 --x86 --powerpc --ia64 --arm --armthumb \
  14. --sparc --delta -q --quiet -v --verbose -h --help \
  15. -H --long-help -V --version' -- "$cur" ) )
  16. return 0
  17. fi
  18. local split=false
  19. _split_longopt && split=true
  20. local xspec="*.@(xz|lzma)"
  21. case "$prev" in
  22. -@(!(-*)[dlt]*|-decompress|-list|-test))
  23. xspec="!"$xspec
  24. ;;
  25. --files|--files0)
  26. _filedir
  27. return 0
  28. ;;
  29. -C|--check)
  30. COMPREPLY=( $( compgen -W 'crc32 crc64 sha256' -- "$cur" ) )
  31. return 0
  32. ;;
  33. -F|--format)
  34. COMPREPLY=( $( compgen -W 'auto xz lzma raw' -- "$cur" ) )
  35. return 0
  36. ;;
  37. -M|--memory|-S|--suffix|--delta|--lzma1|--lzma2)
  38. # argument required but no completions available
  39. return 0
  40. ;;
  41. -h|--help|-H|--long-help|-V|--version)
  42. # all other arguments are noop with these
  43. return 0
  44. ;;
  45. esac
  46. $split && return 0
  47. _expand || return 0
  48. local IFS=$'\t\n'
  49. COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
  50. $( compgen -d -- "$cur" ) )
  51. } &&
  52. complete -F _xz $filenames xz
  53. # xzdec(1) completion
  54. #
  55. have xzdec &&
  56. _xzdec()
  57. {
  58. COMPREPLY=()
  59. local cur=`_get_cword`
  60. local prev=${COMP_WORDS[COMP_CWORD-1]}
  61. if [[ "$cur" == -* ]]; then
  62. COMPREPLY=( $( compgen -W '-M --memory -h --help -V --version' \
  63. -- "$cur" ) )
  64. return 0
  65. fi
  66. local split=false
  67. _split_longopt && split=true
  68. case "$prev" in
  69. -M|--memory)
  70. # argument required but no completions available
  71. return 0
  72. ;;
  73. -h|--help|-V|--version)
  74. # all other arguments are noop with these
  75. return 0
  76. ;;
  77. esac
  78. $split && return 0
  79. _filedir xz # no lzma support here as of xz 4.999.8beta
  80. } &&
  81. complete -F _xzdec $filenames xzdec
  82. # Local variables:
  83. # mode: shell-script
  84. # sh-basic-offset: 4
  85. # sh-indent-comment: t
  86. # indent-tabs-mode: nil
  87. # End:
  88. # ex: ts=4 sw=4 et filetype=sh