xrnlib-cli-autocomplete.sh 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. #!/bin/bash
  2. _xrnlib_completitions() {
  3. # COMP_WORDS=( "--encoding-conf" "-encoding-param" "mak" )
  4. # COMP_CWORD=${#COMP_WORDS[@]}
  5. ###########################
  6. # simulate a command line #
  7. ###########################
  8. all_possible_args=("" "--help" "--script" "--example" "--version" "--decoding-conf" "-compiled-param" "-encoding-param" "-no-param" "-init-file" "-no-password" "-password-str" "-no-running-err" "-running-err-th" "-running-war-th" "-no-disparity-err" "-disparity-err-th" "-disparity-war-th" "--encoding-conf" "-compiled-param" "-encoding-param" "-no-param" "-init-file" "-no-password" "-password-str" "-no-running-err" "-running-err-th" "-running-war-th" "-no-disparity-err" "-disparity-err-th" "-disparity-war-th" "--arithmetic-conf" "-point" "-binomial-key" "-monomial-key" "-start-point" "-monomial-commitment" "-binomial-commitment" "-monomial-response" "-monomial-proof" "-monovalent-key" "-polyvalent-proof" "-polyvalent-key" "-sym-signature" "-asy-signature" "-ring-signature" "-hash" "-sym-certificate" "-asy-certificate" "-state-size" "-crc-bits" "-rnd-str" "-no-thread" "-no-const-exec-time" "--sequence-conf" "-xmatrix-comp" "-xmatrix" "--permutation-conf" "-no-permutation-key" "-arch" "-shared-lib" "--logging-conf" "-lib-error-log" "-lib-warning-log" "-lib-info-log" "-lib-debug-log" "-command-line-log" "-no-lib-error-log" "-no-lib-warning-log" "-no-command-line-log" "-debug-seed" "-force-append" "-force-write" "--dump-encoding-param" "-encoding-param" "--decode-encode" "-to-decode" "-to-encode" "--mine-xmatrix-comp-rnd" "-prob-ones" "-max-tries" "-xmatrix-comp" "-random" "-pseudo-random" "--mine-xmatrix-comp-ot" "-min-ones-per-row" "-max-ones-per-row" "-max-tries" "-xmatrix-comp" "-random" "-pseudo-random" "--permute-xmatrix-comp-rnd" "-xmatrix-comp-dst" "--permute-xmatrix-comp-det" "-xmatrix-comp-dst" "--permute-xmatrix-comp-sec" "-xmatrix-comp-dst" "--decompress-xmatrix" "-xmatrix" "--check-xmatrix-comp" "--check-xmatrix" "--make-point" "-point" "--make-secure-pseudo-random-number" "-next-point" "--make-start-point" "-start-point" "--make-monomial-key" "-monomial-key" "--make-binomial-key" "-binomial-key" "--exchange-monomial-key" "-external-binomial-key" "-shared-monomial-key" "--make-monovalent-key" "-monovalent-key" "-polyvalent-key" "-polyvalent-proof" "-start-timestamp" "-end-timestamp" "--exchange-polyvalent-key" "-external-monovalent-key" "-shared-polyvalent-key" "--check-monovalent-key" "--make-commitment-binomial-key" "-monomial-commitment" "-binomial-commitment" "--make-commitment-sym-signature" "-plain-text" "-monomial-commitment" "-binomial-commitment" "--make-commitment-sym-certificate" "-monomial-commitment" "-binomial-commitment" "--make-response" "-monomial-response" "--make-monomial-proof" "-monomial-proof" "--make-monomial-proof-sym-signature" "-monomial-proof" "-plain-text" "--make-monomial-proof-sym-certificate" "-monomial-proof" "--check-monomial-proof" "--check-monomial-proof-sym-signature" "-plain-text" "--check-monomial-proof-sym-certificate" "--make-signature-symmetric" "-plain-text" "-symmetric-signature" "--make-signature-asymmetric" "-plain-text" "-asymmetric-signature" "--make-ring-signature" "-add-decoy-binomial-key" "-plain-text" "-verifier-binomial-key" "-ring-signature" "--make-certificate-symmetric" "-subject-monovalent-key" "-subject-str" "-symmetric-certificate" "-start-timestamp" "-end-timestamp" "--make-certificate-asymmetric" "-subject-binomial-key" "-subject-str" "-asymmetric-certificate" "-start-timestamp" "-end-timestamp" "--check-signature-symmetric" "-plain-text" "--check-signature-asymmetric" "-plain-text" "--check-ring-signature" "-signer-binomial-key" "-plain-text" "--check-certificate-symmetric" "--check-certificate-asymmetric" "--make-hash" "-plain-text" "-hash" "--make-checksum" "-plain-text" "-checksum-text" "--check-checksum" "-plain-text" "-checksum-text" "--check-hash" "-plain-text" "--convert-hash-to-monomial-key" "-monomial-key" "--convert-hash-to-point" "-point" "--convert-point-to-monomial-key" "-monomial-key" "--convert-monomial-key-to-point" "-point" "--convert-binomial-key-to-start-point" "-start-point" "--convert-start-point-to-point" "-point" "--convert-point-to-start-point" "-start-point" "--convert-monomial-key-to-monomial-commitment" "-monomial-commitment" "--convert-monomial-commitment-to-monomial-key" "-monomial-key" "--convert-symmetric-certificate-to-monovalent-key" "-monovalent-key" "--convert-asymmetric-certificate-to-binomial-key" "-binomial-key" "--convert-asymmetric-signature-to-binomial-key" "-binomial-key" "--convert-symmetric-signature-to-binomial-key" "-binomial-key" "--convert-binomial-key-to-asymmetric-signature" "-asymmetric-signature" "--convert-binomial-key-to-symmetric-signature" "-symmetric-signature" "--split-symmetric" "-plain-text" "-challenge-text" "-solution-text" "--encrypt-asymmetric" "-plain-text" "-cipher-text" "--encrypt-symmetric" "-plain-text" "-cipher-text" "--join-symmetric" "-plain-text" "-challenge-text" "-solution-text" "--decipher-asymmetric" "-plain-text" "-cipher-text" "--decipher-symmetric" "-plain-text" "-cipher-text" "--check-complete-block" "-block-file" "--make-block" "-offset" "-length" "-tag" "-plain-text" "-block-file" "--combine-blocks" "-block-file" "-combined-block-file" "--strip-header-from-block" "-block-file" "-plain-text" "--print-header" "-xrn-file" "--print-lib-info" "--get-capacity" "-envelop-file" "-disable-folding" "--make-steganography-block" "-source-file" "-envelop-file" "-embedded-file" "-disable-folding" "-offset" "-length" "-tag" "--extract-steganography-block" "-embedded-file" "-block-file")
  9. tree_of_commands="--logging-conf --help +--logging-conf --example +--logging-conf --script +--encoding-conf --logging-conf --dump-encoding-param +--decoding-conf --encoding-conf --logging-conf --decode-encode +--decoding-conf --encoding-conf --logging-conf --arithmetic-conf --permutation-conf --mine-xmatrix-comp-rnd +--decoding-conf --encoding-conf --logging-conf --arithmetic-conf --permutation-conf --mine-xmatrix-comp-ot +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --permute-xmatrix-comp-rnd +--decoding-conf --encoding-conf --sequence-conf --permutation-conf --logging-conf --permute-xmatrix-comp-det +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --permute-xmatrix-comp-sec +--decoding-conf --encoding-conf --sequence-conf --permutation-conf --logging-conf --decompress-xmatrix +--decoding-conf --sequence-conf --permutation-conf --logging-conf --check-xmatrix-comp +--decoding-conf --sequence-conf --permutation-conf --logging-conf --check-xmatrix +--encoding-conf --arithmetic-conf --permutation-conf --logging-conf --make-point +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-secure-pseudo-random-number +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-start-point +--encoding-conf --arithmetic-conf --permutation-conf --logging-conf --make-monomial-key +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-binomial-key +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --exchange-monomial-key +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-monovalent-key +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --exchange-polyvalent-key +--decoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --check-monovalent-key +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-commitment-binomial-key +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-commitment-sym-signature +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-commitment-sym-certificate +--encoding-conf --arithmetic-conf --permutation-conf --logging-conf --make-response +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-monomial-proof +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-monomial-proof-sym-signature +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-monomial-proof-sym-certificate +--decoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --check-monomial-proof +--decoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --check-monomial-proof-sym-signature +--decoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --check-monomial-proof-sym-certificate +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-signature-symmetric +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-signature-asymmetric +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-ring-signature +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-certificate-symmetric +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-certificate-asymmetric +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --check-signature-symmetric +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --check-signature-asymmetric +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --check-ring-signature +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --check-certificate-symmetric +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --check-certificate-asymmetric +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --make-hash +--logging-conf --make-checksum +--logging-conf --check-checksum +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --check-hash +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-hash-to-monomial-key +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-hash-to-point +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-point-to-monomial-key +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-monomial-key-to-point +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-binomial-key-to-start-point +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-start-point-to-point +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-point-to-start-point +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-monomial-key-to-monomial-commitment +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-monomial-commitment-to-monomial-key +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-symmetric-certificate-to-monovalent-key +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-asymmetric-certificate-to-binomial-key +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-asymmetric-signature-to-binomial-key +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-symmetric-signature-to-binomial-key +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-binomial-key-to-asymmetric-signature +--decoding-conf --encoding-conf --arithmetic-conf --permutation-conf --logging-conf --convert-binomial-key-to-symmetric-signature +--encoding-conf --arithmetic-conf --permutation-conf --logging-conf --split-symmetric +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --encrypt-asymmetric +--decoding-conf --encoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --encrypt-symmetric +--decoding-conf --permutation-conf --logging-conf --join-symmetric +--decoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --decipher-asymmetric +--decoding-conf --arithmetic-conf --sequence-conf --permutation-conf --logging-conf --decipher-symmetric +--logging-conf --check-complete-block +--logging-conf --make-block +--logging-conf --combine-blocks +--logging-conf --strip-header-from-block +--decoding-conf --logging-conf --permutation-conf --print-header +--logging-conf --print-lib-info +--logging-conf --get-capacity +--encoding-conf --logging-conf --make-steganography-block +--decoding-conf --logging-conf --extract-steganography-block "
  10. possible_first_commands=( "--example --scripts --help --version --check-checksum" "--check-complete-block" "--combine-blocks" "--decoding-conf" "--encoding-conf" "--example" "--get-capacity" "--help" "--logging-conf" "--make-block" "--make-checksum" "--print-lib-info" "--script" "--strip-header-from-block" )
  11. options_followed_by_w_path=("-asymmetric-certificate" "-asymmetric-signature" "-binomial-commitment" "-binomial-key" "-block-file" "-challenge-text" "-checksum-text" "-cipher-text" "-combined-block-file" "-command-line-log" "-embedded-file" "-encoding-param" "-hash" "-lib-debug-log" "-lib-info-log" "-lib-warning-log" "-monomial-commitment" "-monomial-key" "-monomial-proof" "-monomial-response" "-monovalent-key" "-next-point" "-plain-text" "-point" "-polyvalent-key" "-polyvalent-proof" "-ring-signature" "-shared-monomial-key" "-shared-polyvalent-key" "-signer-binomial-key" "-solution-text" "-start-point" "-symmetric-certificate" "-symmetric-signature" "-to-encode" "-xmatrix" "-xmatrix-comp" "-xmatrix-comp-dst" )
  12. options_followed_by_r_path=("-add-decoy-binomial-key" "-asy-certificate" "-asy-signature" "-binomial-commitment" "-binomial-key" "-block-file" "-challenge-text" "-checksum-text" "-cipher-text" "-embedded-file" "-encoding-param" "-envelop-file" "-external-binomial-key" "-external-monovalent-key" "-hash" "-init-file" "-monomial-commitment" "-monomial-key" "-monomial-proof" "-monomial-response" "-monovalent-key" "-plain-text" "-point" "-polyvalent-key" "-polyvalent-proof" "-ring-signature" "-shared-lib" "-solution-text" "-source-file" "-start-point" "-subject-binomial-key" "-subject-monovalent-key" "-sym-certificate" "-sym-signature" "-to-decode" "-verifier-binomial-key" "-xmatrix" "-xmatrix-comp" "-xrn-file" )
  13. ##########################################
  14. # create command and strip_command lists #
  15. ##########################################
  16. list_strip_commands=()
  17. list_of_commands=()
  18. for word in ${all_possible_args[@]}; do
  19. # check if it is a command
  20. if [[ $word == --* ]]; then
  21. list_of_commands+=("$word")
  22. if [ "$word" != "--help" ] && [ "$word" != "--example" ] && [ "$word" != "--script" ] && [ "$word" != "--version" ] && \
  23. [ "$word" != "--decoding-conf" ] && [ "$word" != "--encoding-conf" ] && [ "$word" != "--permutation-conf" ] && \
  24. [ "$word" != "--sequence-conf" ] ; then
  25. if [ "$word" != "--arithmetic-conf" ] && [ "$word" != "--logging-conf" ] ; then
  26. list_strip_commands+=("${word#??}")
  27. fi
  28. fi
  29. fi
  30. done
  31. ########################
  32. # get list of commands #
  33. ########################
  34. given_list_command=()
  35. given_list_options=()
  36. last_command=""
  37. command_found=0
  38. help_found=0
  39. examples_scripts_found=0
  40. examples_scripts_rnd_found=0
  41. version_found=0
  42. arithmetic_conf_found=0
  43. sequence_conf_found=0
  44. permutation_conf_found=0
  45. encoding_conf_found=0
  46. decoding_conf_found=0
  47. option_with_w_path=0
  48. do_not_suggest_conf=0
  49. for word in ${COMP_WORDS[@]}; do
  50. if [[ $word == --* ]]; then
  51. command_found=0
  52. # check if command is complete
  53. for command in ${list_of_commands[@]}; do
  54. if [ "$command" == "$word" ] ; then
  55. command_found=1
  56. fi
  57. done
  58. if [ "$command_found" -eq 1 ] ; then
  59. given_list_command+=("$word")
  60. given_list_options=()
  61. last_command="$word"
  62. if [ "$word" == "--help" ] ; then
  63. help_found=1
  64. do_not_suggest_conf=1
  65. elif [ "$word" == "--example" ] || [ "$word" == "--script" ] ; then
  66. examples_scripts_found=1
  67. do_not_suggest_conf=1
  68. elif [ "$word" == "--version" ] ; then
  69. version_found=1
  70. do_not_suggest_conf=1
  71. elif [ "$word" == "--decoding-conf" ] ; then
  72. decoding_conf_found=1
  73. elif [ "$word" == "--encoding-conf" ] ; then
  74. encoding_conf_found=1
  75. elif [ "$word" == "--arithmetic-conf" ] ; then
  76. arithmetic_conf_found=1
  77. elif [ "$word" == "--sequence-conf" ] ; then
  78. sequence_conf_found=1
  79. elif [ "$word" == "--permutation-conf" ] ; then
  80. permutation_conf_found=1
  81. else
  82. do_not_suggest_conf=1
  83. fi
  84. fi
  85. elif [[ $word == -* ]]; then
  86. if [ "$examples_scripts_found" -eq 1 ] ; then
  87. if [ "$word" == "-rnd" ] ; then
  88. examples_scripts_rnd_found=1
  89. fi
  90. fi
  91. given_list_options+=("$word")
  92. elif [ "$word" == ">" ] || [ "$word" == ">>" ]; then
  93. option_with_w_path=1
  94. fi
  95. done
  96. len_given_list_command=${#given_list_command[@]}
  97. ####################################
  98. # get options for the last command #
  99. ####################################
  100. get_options=0
  101. options_tmp=()
  102. options=()
  103. for arg in ${all_possible_args[@]}; do
  104. if [[ $arg == $last_command ]]; then
  105. get_options=1
  106. elif [[ $arg == --* ]]; then
  107. get_options=0
  108. else
  109. if [ $get_options -eq 1 ] ;then
  110. options_tmp+=("$arg")
  111. fi
  112. fi
  113. done
  114. ## strip already seen elements from options
  115. len=${#options_tmp[@]}
  116. for (( i=0; i<$((len)); i++ )); do
  117. found=0
  118. for option in ${given_list_options[@]}; do
  119. if [ "${options_tmp[$i]}" == "$option" ]; then
  120. if [ "-add-decoy-binomial-key" != "$option" ]; then
  121. found=1
  122. fi
  123. if [ "-block-file" != "$option" ]; then
  124. found=1
  125. fi
  126. fi
  127. done
  128. if [ "$found" -eq 0 ]; then
  129. options+=("${options_tmp[$i]}")
  130. fi
  131. done
  132. #############
  133. # get paths #
  134. #############
  135. option_with_r_path=0
  136. for arg in ${options_followed_by_r_path[@]}; do
  137. for option in ${options_tmp[@]}; do
  138. if [ "$option" == "$arg" ] ; then
  139. if [ "${COMP_WORDS[-2]}" == "$arg" ] || [ "${COMP_WORDS[-1]}" == "$arg" ]; then
  140. option_with_r_path=1
  141. fi
  142. fi
  143. done
  144. done
  145. if [ "$option_with_r_path" -eq 1 ]; then
  146. if [ "${COMP_WORDS[-1]}" == "" ]; then
  147. possible_paths="$( ls . 2>/dev/null | tr -s '\n' ' ' )"
  148. else
  149. possible_paths="$( ls ${COMP_WORDS[-1]}* 2>/dev/null | tr -s '\n' ' ' )"
  150. fi
  151. else
  152. possible_paths=""
  153. fi
  154. for arg in ${options_followed_by_w_path[@]}; do
  155. if [ "$COMP_CWORD" -ge 2 ]; then
  156. if [ "${COMP_WORDS[-2]}" == "$arg" ]; then
  157. if [ "$option_with_r_path" -eq 0 ]; then
  158. option_with_w_path=1
  159. fi
  160. fi
  161. fi
  162. done
  163. ###############################
  164. # check if a space is reqired #
  165. ###############################
  166. add_space=0
  167. for arg in ${all_possible_args[@]}; do
  168. if [ "${COMP_WORDS[-1]}" == "$arg" ]; then
  169. add_space=1
  170. fi
  171. done
  172. ###############################
  173. # get possible commands lists #
  174. ###############################
  175. str_to_eval="possible_commands=\$(echo \" $tree_of_commands \" | tr -s '+' '\n' "
  176. if [ "$do_not_suggest_conf" -eq 1 ] ; then
  177. str_to_eval="$str_to_eval | grep -ve --permutation-conf | grep -ve --decoding-conf | grep -ve --encoding-conf | grep -ve --arithmetic-conf | grep -ve --sequence-conf "
  178. elif [ "$permutation_conf_found" -eq 1 ] && [ "$encoding_conf_found" -eq 0 ] && [ "$decoding_conf_found" -eq 0 ] && [ "$arithmetic_conf_found" -eq 0 ] && [ "$sequence_conf_found" -eq 0 ] ; then
  179. str_to_eval="$str_to_eval | grep -ve --decoding-conf | grep -ve --encoding-conf | grep -ve --arithmetic-conf | grep -ve --sequence-conf "
  180. elif [ "$sequence_conf_found" -eq 1 ] && [ "$encoding_conf_found" -eq 0 ] && [ "$decoding_conf_found" -eq 0 ] && [ "$arithmetic_conf_found" -eq 0 ] ; then
  181. str_to_eval="$str_to_eval | grep -ve --decoding-conf | grep -ve --encoding-conf | grep -ve --arithmetic-conf "
  182. elif [ "$arithmetic_conf_found" -eq 1 ] && [ "$encoding_conf_found" -eq 0 ] && [ "$decoding_conf_found" -eq 0 ] ; then
  183. str_to_eval="$str_to_eval | grep -ve --encoding-conf | grep -ve --decoding-conf "
  184. elif [ "$encoding_conf_found" -eq 1 ] && [ "$decoding_conf_found" -eq 0 ] ; then
  185. str_to_eval="$str_to_eval | grep -ve --decoding-conf "
  186. fi
  187. for command in ${given_list_command[@]}; do
  188. str_to_eval="$str_to_eval | grep -e $command "
  189. done
  190. str_to_eval="$str_to_eval | tr -s ' ' '\n' | sort | uniq "
  191. for command in ${given_list_command[@]}; do
  192. str_to_eval="$str_to_eval | grep -ve $command "
  193. done
  194. str_to_eval="$str_to_eval | tr -s '\n' ' ' )"
  195. eval "$str_to_eval"
  196. if [ "$permutation_conf_found" -eq 1 ] ; then
  197. str_to_eval="possible_commands=\$(echo ${possible_commands[@]} | sed 's/--decoding-conf//g' | sed 's/--encoding-conf//g' | sed 's/--arithmetic-conf//g' | sed 's/--sequence-conf//g')"
  198. elif [ "$sequence_conf_found" -eq 1 ] ; then
  199. str_to_eval="possible_commands=\$(echo ${possible_commands[@]} | sed 's/--decoding-conf//g' | sed 's/--encoding-conf//g' | sed 's/--arithmetic-conf//g')"
  200. eval "$str_to_eval"
  201. elif [ "$arithmetic_conf_found" -eq 1 ] ; then
  202. str_to_eval="possible_commands=\$(echo ${possible_commands[@]} | sed 's/--decoding-conf//g' | sed 's/--encoding-conf//g')"
  203. eval "$str_to_eval"
  204. elif [ "$encoding_conf_found" -eq 1 ] ; then
  205. str_to_eval="possible_commands=\$(echo ${possible_commands[@]} | sed 's/--decoding-conf//g')"
  206. eval "$str_to_eval"
  207. fi
  208. #############################
  209. # sort options and commands #
  210. #############################
  211. sorted_possible_first_commands=($(echo "${possible_first_commands[*]}" | tr ' ' '\n' | sort))
  212. sorted_list_strip_commands=($(echo "${list_strip_commands[*]}" | tr ' ' '\n' | sort))
  213. sorted_possible_commands=($(echo "${possible_commands[*]}" | tr ' ' '\n' | sort))
  214. sorted_options=($(echo "${options[*]}" | tr ' ' '\n' | sort))
  215. ############################
  216. # get possible suggestions #
  217. ############################
  218. possible_suggestions=""
  219. if [ "$option_with_r_path" -eq 1 ]; then
  220. possible_suggestions="$possible_paths"
  221. elif [ "$option_with_w_path" -eq 1 ]; then
  222. possible_suggestions=""
  223. elif [ "$help_found" -eq 1 ] && [ "$COMP_CWORD" -le 6 ] ; then
  224. possible_suggestions="${sorted_list_strip_commands[@]}"
  225. elif [ "$examples_scripts_found" -eq 1 ] && [ "$examples_scripts_rnd_found" -eq 0 ] && [ "$COMP_CWORD" -le 6 ] ; then
  226. possible_suggestions="-rnd "
  227. possible_suggestions="$possible_suggestions ${sorted_list_strip_commands[@]}"
  228. elif [ "$examples_scripts_found" -eq 1 ] && [ "$examples_scripts_rnd_found" -eq 1 ] && [ "$COMP_CWORD" -le 7 ] ; then
  229. possible_suggestions="${sorted_list_strip_commands[@]}"
  230. elif [ "$version_found" -eq 1 ] ; then
  231. possible_suggestions=""
  232. elif [ "$examples_scripts_found" -eq 0 ] && [ "$examples_scripts_found" -eq 0 ] && [ "$version_found" -eq 0 ] && [ "$COMP_CWORD" -le 1 ]; then
  233. possible_suggestions="${sorted_possible_first_commands[@]}"
  234. elif [ "$examples_scripts_found" -eq 0 ] && [ "$examples_scripts_found" -eq 0 ] && [ "$version_found" -eq 0 ] ; then
  235. possible_suggestions="${sorted_options[@]}"
  236. possible_suggestions="$possible_suggestions ${sorted_possible_commands[@]}"
  237. fi
  238. possible_suggestions="$possible_suggestions dummy"
  239. possible_suggestions_list=()
  240. while read -r -d ' ' element; do
  241. if [ -n "$element" ]; then
  242. possible_suggestions_list+=("$element")
  243. fi
  244. done <<< "$possible_suggestions"
  245. ##############################################################
  246. # check if the last work written completely matches one word #
  247. ##############################################################
  248. complete_matcth=0
  249. if [ "${COMP_WORDS[-1]}" == "-rnd" ]; then
  250. complete_matcth=1
  251. fi
  252. for arg in ${all_possible_args[@]}; do
  253. if [ "${COMP_WORDS[-1]}" == "$arg" ]; then
  254. complete_matcth=1
  255. fi
  256. done
  257. ###################
  258. # get suggestions #
  259. ###################
  260. COMPREPLY=()
  261. if [ "$add_space" -eq 1 ]; then
  262. COMPREPLY+=("${COMP_WORDS[-1]}")
  263. elif [ "$option_with_r_path" -eq 1 ]; then
  264. for suggestion in "${possible_suggestions_list[@]}"; do
  265. COMPREPLY+=("$suggestion")
  266. done
  267. elif [ "$option_with_w_path" -eq 1 ]; then
  268. COMPREPLY=()
  269. elif [ "$complete_matcth" -eq 0 ] ; then
  270. if [[ "-rnd" == *"${COMP_WORDS[-1]}"* ]] && [ "$examples_scripts_found" -eq 1 ] && [ "$examples_scripts_rnd_found" -eq 0 ]; then
  271. COMPREPLY+=("-rnd")
  272. fi
  273. for suggestion in "${possible_suggestions_list[@]}"; do
  274. if [[ "$suggestion" == "${COMP_WORDS[-1]}"* ]]; then
  275. COMPREPLY+=("$suggestion")
  276. fi
  277. done
  278. else
  279. for suggestion in "${possible_suggestions_list[@]}"; do
  280. COMPREPLY+=("$suggestion")
  281. done
  282. fi
  283. #echo "COMPREPLY ${COMPREPLY[@]}"
  284. }
  285. complete -o nosort -F _xrnlib_completitions xrnlib-cli
  286. #_xrnlib_completitions