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 / java < prev    next >
Encoding:
Text File  |  2010-11-16  |  11.4 KB  |  425 lines

  1. # bash completion for java, javac and javadoc
  2.  
  3. # available path elements completion
  4. have java && {
  5. _java_path()
  6. {
  7.     cur=${cur##*:}
  8.     _filedir '@(jar|zip)'
  9. }
  10.  
  11. # exact classpath determination
  12. _java_find_classpath()
  13. {
  14.     local i
  15.  
  16.     # search first in current options
  17.     for (( i=1; i < COMP_CWORD; i++ )); do
  18.         if [[ "${COMP_WORDS[i]}" == -@(cp|classpath) ]]; then
  19.             classpath=${COMP_WORDS[i+1]}
  20.             break
  21.         fi
  22.     done
  23.  
  24.     # default to environment
  25.     [ -z "$classpath" ] && classpath=$CLASSPATH
  26.  
  27.     # default to current directory
  28.     [ -z "$classpath" ] && classpath=.
  29. }
  30.  
  31. # exact sourcepath determination
  32. _java_find_sourcepath()
  33. {
  34.     local i
  35.  
  36.     # search first in current options
  37.     for (( i=1; i < COMP_CWORD; i++ )); do
  38.         if [[ "${COMP_WORDS[i]}" == -sourcepath ]]; then
  39.             sourcepath=${COMP_WORDS[i+1]}
  40.             break
  41.         fi
  42.     done
  43.  
  44.     # default to classpath
  45.     if [ -z "$sourcepath" ]; then
  46.         _java_find_classpath
  47.         sourcepath=$classpath
  48.     fi
  49. }
  50.  
  51. # available classes completion
  52. _java_classes()
  53. {
  54.     local classpath i
  55.  
  56.     # find which classpath to use
  57.     _java_find_classpath
  58.  
  59.     # convert package syntax to path syntax
  60.     cur=${cur//.//}
  61.     # parse each classpath element for classes
  62.     for i in ${classpath//:/ }; do
  63.         if [[ -r $i && "$i" == *.@(jar|zip) ]]; then
  64.             if type zipinfo &>/dev/null; then
  65.                 COMPREPLY=( "${COMPREPLY[@]}" $( zipinfo -1 \
  66.                     "$i" "$cur*" 2>/dev/null | \
  67.                     command grep '^[^$]*\.class$' ) )
  68.             else
  69.                 COMPREPLY=( "${COMPREPLY[@]}" $( jar tf "$i" \
  70.                     "$cur" | command grep '^[^$]*\.class$' ) )
  71.             fi
  72.  
  73.         elif [ -d $i ]; then
  74.             # Intentionally looking for *.class only in $i (not subdirs),
  75.             # see Debian bug #496828.
  76.             COMPREPLY=( "${COMPREPLY[@]}"
  77.                 $( command ls $i/$cur*.class 2>/dev/null | \
  78.                     sed -ne '/\$/d' -e "s|^$i//*||p" ) )
  79.  
  80.             # FIXME: if we have foo.class and foo/, the completion
  81.             # returns "foo/"... how to give precedence to files
  82.             # over directories?
  83.         fi
  84.     done
  85.  
  86.     # remove class extension
  87.     COMPREPLY=( ${COMPREPLY[@]%.class} )
  88.     # convert path syntax to package syntax
  89.     COMPREPLY=( ${COMPREPLY[@]//\//.} )
  90. }
  91.  
  92. # available packages completion
  93. _java_packages()
  94. {
  95.     local sourcepath i
  96.  
  97.     # find which sourcepath to use
  98.     _java_find_sourcepath
  99.  
  100.     # convert package syntax to path syntax
  101.     cur=${cur//.//}
  102.     # parse each sourcepath element for packages
  103.     for i in ${sourcepath//:/ }; do
  104.         if [ -d $i ]; then
  105.             COMPREPLY=( "${COMPREPLY[@]}" $( command ls -F -d \
  106.                 $i/$cur* 2>/dev/null | sed -e 's|^'$i'/||' ) )
  107.         fi
  108.     done
  109.     # keep only packages
  110.     COMPREPLY=( $( tr " " "\n" <<<"${COMPREPLY[@]}" | command grep "/$" ) )
  111.     # remove packages extension
  112.     COMPREPLY=( ${COMPREPLY[@]%/} )
  113.     # convert path syntax to package syntax
  114.     cur=${COMPREPLY[@]//\//.}
  115. }
  116.  
  117. # java completion
  118. #
  119. _java()
  120. {
  121.     local cur prev i
  122.  
  123.     COMPREPLY=()
  124.     _get_comp_words_by_ref cur prev
  125.  
  126.     for ((i=1; i < $COMP_CWORD; i++)); do
  127.         case ${COMP_WORDS[$i]} in
  128.             -cp|-classpath)
  129.                 ((i++)) # skip the classpath string.
  130.                 ;;
  131.             -*)
  132.                 # this is an option, not a class/jarfile name.
  133.                 ;;
  134.             *)
  135.                 # once we've seen a class, just do filename completion
  136.                 _filedir
  137.                 return 0
  138.                 ;;
  139.         esac
  140.     done
  141.  
  142.     case $prev in
  143.         -cp|-classpath)
  144.             _java_path
  145.             return 0
  146.             ;;
  147.     esac
  148.  
  149.     if [[ "$cur" == -* ]]; then
  150.         # relevant options completion
  151.         COMPREPLY=( $( compgen -W '-client -hotspot -server -classic \
  152.             -classpath -D -verbose -verbose:class \
  153.             -verbose:gc -version:jni -version \
  154.             -showversion -help -X -jar \
  155.             -enableassertions -disableassertions \
  156.             -enablesystemassertions -disablesystemassertions ' -- "$cur" ) )
  157.     else
  158.         if [[ "$prev" == -jar ]]; then
  159.             # jar file completion
  160.             _filedir jar
  161.         else
  162.             # classes completion
  163.             _java_classes
  164.         fi
  165.     fi
  166. }
  167. complete -F _java -o filenames java
  168. }
  169.  
  170. have javadoc &&
  171. _javadoc()
  172. {
  173.     COMPREPLY=()
  174.     local cur prev classpath
  175.  
  176.     _get_comp_words_by_ref cur prev
  177.  
  178.     case $prev in
  179.         -overview|-helpfile|-stylesheetfile)
  180.             _filedir
  181.             return 0
  182.             ;;
  183.         -d)
  184.             _filedir -d
  185.             return 0
  186.             ;;
  187.         -classpath|-bootclasspath|-docletpath|-sourcepath|-extdirs)
  188.             _java_path
  189.             return 0
  190.             ;;
  191.     esac
  192.  
  193.     if [[ "$cur" == -* ]]; then
  194.         # relevant options completion
  195.         COMPREPLY=( $( compgen -W '-overview -public -protected \
  196.             -package -private -help -doclet -docletpath \
  197.             -sourcepath -classpath -exclude -subpackages \
  198.             -breakiterator -bootclasspath -source -extdirs \
  199.             -verbose -locale -encoding -J -d -use -version \
  200.             -author -docfilessubdirs -splitindex \
  201.             -windowtitle -doctitle -header -footer -bottom \
  202.             -link -linkoffline -excludedocfilessubdir \
  203.             -group -nocomment -nodeprecated -noqualifier \
  204.             -nosince -nodeprecatedlist -notree -noindex \
  205.             -nohelp -nonavbar -quiet -serialwarn -tag \
  206.             -taglet -tagletpath -charset -helpfile \
  207.             -linksource -stylesheetfile -docencoding' -- "$cur" ) )
  208.     else
  209.         # source files completion
  210.         _filedir java
  211.         # packages completion
  212.         _java_packages
  213.     fi
  214. } &&
  215. complete -F _javadoc -o filenames javadoc
  216.  
  217. have javac &&
  218. _javac()
  219. {
  220.     COMPREPLY=()
  221.     local cur prev
  222.  
  223.     _get_comp_words_by_ref cur prev
  224.  
  225.     case $prev in
  226.         -d)
  227.             _filedir -d
  228.             return 0
  229.             ;;
  230.         -classpath|-bootclasspath|-sourcepath|-extdirs)
  231.             _java_path
  232.             return 0
  233.             ;;
  234.     esac
  235.  
  236.     if [[ "$cur" == -* ]]; then
  237.         # relevant options completion
  238.         COMPREPLY=( $( compgen -W '-g -g:none -g:lines -g:vars \
  239.             -g:source -O -nowarn -verbose -deprecation -classpath \
  240.             -sourcepath -bootclasspath -extdirs -d -encoding -source \
  241.             -target -help' -- "$cur" ) )
  242.     else
  243.         # source files completion
  244.         _filedir java
  245.     fi
  246. } &&
  247. complete -F _javac -o filenames javac
  248.  
  249. have pack200 &&
  250. _pack200()
  251. {
  252.     COMPREPLY=()
  253.     local cur prev
  254.     _get_comp_words_by_ref cur prev
  255.  
  256.     case $prev in
  257.         -S|--segment-limit|-P|--pass-file|-C|--class-attribute|\
  258.         -F|--field-attribute|-M|--method-attribute|-D|--code-attribute|\
  259.         '-?'|-h|--help|-V|--version|-J)
  260.             return 0
  261.             ;;
  262.         -E|--effort)
  263.             COMPREPLY=( $( compgen -W '0 1 2 3 4 5 6 7 8 9' -- "$cur" ) )
  264.             return 0
  265.             ;;
  266.         -H|--deflate-hint)
  267.             COMPREPLY=( $( compgen -W 'true false keep' -- "$cur" ) )
  268.             return 0
  269.             ;;
  270.         -m|--modification-time)
  271.             COMPREPLY=( $( compgen -W 'latest keep' -- "$cur" ) )
  272.             return 0
  273.             ;;
  274.         -U|--unknown-attribute)
  275.             COMPREPLY=( $( compgen -W 'error strip pass' -- "$cur" ) )
  276.             return 0
  277.             ;;
  278.         -f|--config-file)
  279.             _filedir properties
  280.             return 0
  281.             ;;
  282.         -l|--log-file)
  283.             COMPREPLY=( $( compgen -W '-' -- "$cur" ) )
  284.             _filedir log
  285.             return 0
  286.             ;;
  287.     esac
  288.  
  289.     # Check if a pack or a jar was already given.
  290.     local i pack=false jar=false
  291.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )) ; do
  292.         case ${COMP_WORDS[i]} in
  293.             *.pack|*.pack.gz) pack=true ;;
  294.             *.jar) jar=true ;;
  295.         esac
  296.     done
  297.  
  298.     if ! $pack ; then
  299.         if [[ "$cur" == -* ]] ; then
  300.             COMPREPLY=( $( compgen -W '--no-gzip --gzip --strip-debug \
  301.                 --no-keep-file-order --segment-limit= --effort= \
  302.                 --deflate-hint= --modification-time= --pass-file= \
  303.                 --unknown-attribute= --class-attribute= --field-attribute= \
  304.                 --method-attribute= --code-attribute= --config-file= \
  305.                 --verbose --quiet --log-file= --help --version -J' -- "$cur" ) )
  306.             [[ ${#COMPREPLY[@]} -eq 1 && ${COMPREPLY[0]} == *= ]] && \
  307.                 type compopt &>/dev/null && compopt -o nospace
  308.         else
  309.             _filedir 'pack?(.gz)'
  310.         fi
  311.     elif ! $jar ; then
  312.         _filedir jar
  313.     fi
  314. } &&
  315. complete -F _pack200 pack200
  316.  
  317. have unpack200 &&
  318. _unpack200()
  319. {
  320.     COMPREPLY=()
  321.     local cur prev
  322.     _get_comp_words_by_ref cur prev
  323.  
  324.     case $prev in
  325.         '-?'|-h|--help|-V|--version|-J)
  326.             return 0
  327.             ;;
  328.         -H|--deflate-hint)
  329.             COMPREPLY=( $( compgen -W 'true false keep' -- "$cur" ) )
  330.             return 0
  331.             ;;
  332.         -l|--log-file)
  333.             COMPREPLY=( $( compgen -W '-' -- "$cur" ) )
  334.             _filedir log
  335.             return 0
  336.             ;;
  337.     esac
  338.  
  339.     # Check if a pack or a jar was already given.
  340.     local i pack=false jar=false
  341.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )) ; do
  342.         case ${COMP_WORDS[i]} in
  343.             *.pack|*.pack.gz) pack=true ;;
  344.             *.jar) jar=true ;;
  345.         esac
  346.     done
  347.  
  348.     if ! $pack ; then
  349.         if [[ "$cur" == -* ]] ; then
  350.             COMPREPLY=( $( compgen -W '--deflate-hint= --remove-pack-file \
  351.                 --verbose --quiet --log-file= --help --version' -- "$cur" ) )
  352.             [[ ${#COMPREPLY[@]} -eq 1 && ${COMPREPLY[0]} == *= ]] && \
  353.                 type compopt &>/dev/null && compopt -o nospace
  354.         else
  355.             _filedir 'pack?(.gz)'
  356.         fi
  357.     elif ! $jar ; then
  358.         _filedir jar
  359.     fi
  360. } &&
  361. complete -F _unpack200 unpack200
  362.  
  363. have jarsigner &&
  364. _jarsigner()
  365. {
  366.     COMPREPLY=()
  367.     local cur prev
  368.     _get_comp_words_by_ref cur prev
  369.  
  370.     case $prev in
  371.         -keystore)
  372.             COMPREPLY=( $( compgen -W 'NONE' -- "$cur" ) )
  373.             _filedir '@(jks|ks|p12|pfx)'
  374.             return 0
  375.             ;;
  376.         -storepass|-keypass|-sigfile|-digestalg|-sigalg|-tsacert|-altsigner|\
  377.         -altsignerpath|-providerName|-providerClass|-providerArg)
  378.             return 0
  379.             ;;
  380.         -storetype)
  381.             COMPREPLY=( $( compgen -W 'JKS PKCS11 PKCS12' -- "$cur" ) )
  382.             return 0
  383.             ;;
  384.         -signedjar)
  385.             _filedir jar
  386.             return 0
  387.             ;;
  388.         -tsa)
  389.             _filedir
  390.             return 0
  391.             ;;
  392.     esac
  393.  
  394.     # Check if a jar was already given.
  395.     local i jar=false
  396.     for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )) ; do
  397.         if [[ "${COMP_WORDS[i]}" == *.jar && \
  398.             "${COMP_WORDS[i-1]}" != -signedjar ]] ; then
  399.             jar=true
  400.             break
  401.         fi
  402.     done
  403.  
  404.     if ! $jar ; then
  405.         if [[ "$cur" == -* ]] ; then
  406.             # Documented as "should not be used": -internalsf, -sectionsonly
  407.             COMPREPLY=( $( compgen -W '-keystore -storepass -storetype \
  408.                 -keypass -sigfile -signedjar -digestalg -sigalg -verify \
  409.                 -verbose -certs -tsa -tsacert -altsigner -altsignerpath \
  410.                 -protected -providerName -providerClass -providerArg' \
  411.                 -- "$cur" ) )
  412.         fi
  413.         _filedir jar
  414.     fi
  415. } &&
  416. complete -F _jarsigner -o filenames jarsigner
  417.  
  418. # Local variables:
  419. # mode: shell-script
  420. # sh-basic-offset: 4
  421. # sh-indent-comment: t
  422. # indent-tabs-mode: nil
  423. # End:
  424. # ex: ts=4 sw=4 et filetype=sh
  425.