123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- #!/bin/bash
- _xrnlib_completitions() {
- # COMP_WORDS=( "--encoding-conf" "-encoding-param" "mak" )
- # COMP_CWORD=${#COMP_WORDS[@]}
- ###########################
- # simulate a command line #
- ###########################
- 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")
- 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 "
- 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" )
- 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" )
- 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" )
- ##########################################
- # create command and strip_command lists #
- ##########################################
- list_strip_commands=()
- list_of_commands=()
- for word in ${all_possible_args[@]}; do
- # check if it is a command
- if [[ $word == --* ]]; then
- list_of_commands+=("$word")
- if [ "$word" != "--help" ] && [ "$word" != "--example" ] && [ "$word" != "--script" ] && [ "$word" != "--version" ] && \
- [ "$word" != "--decoding-conf" ] && [ "$word" != "--encoding-conf" ] && [ "$word" != "--permutation-conf" ] && \
- [ "$word" != "--sequence-conf" ] ; then
- if [ "$word" != "--arithmetic-conf" ] && [ "$word" != "--logging-conf" ] ; then
- list_strip_commands+=("${word#??}")
- fi
- fi
- fi
- done
- ########################
- # get list of commands #
- ########################
- given_list_command=()
- given_list_options=()
- last_command=""
- command_found=0
- help_found=0
- examples_scripts_found=0
- examples_scripts_rnd_found=0
- version_found=0
- arithmetic_conf_found=0
- sequence_conf_found=0
- permutation_conf_found=0
- encoding_conf_found=0
- decoding_conf_found=0
- option_with_w_path=0
- do_not_suggest_conf=0
- for word in ${COMP_WORDS[@]}; do
- if [[ $word == --* ]]; then
- command_found=0
- # check if command is complete
- for command in ${list_of_commands[@]}; do
- if [ "$command" == "$word" ] ; then
- command_found=1
- fi
- done
- if [ "$command_found" -eq 1 ] ; then
- given_list_command+=("$word")
- given_list_options=()
- last_command="$word"
- if [ "$word" == "--help" ] ; then
- help_found=1
- do_not_suggest_conf=1
- elif [ "$word" == "--example" ] || [ "$word" == "--script" ] ; then
- examples_scripts_found=1
- do_not_suggest_conf=1
- elif [ "$word" == "--version" ] ; then
- version_found=1
- do_not_suggest_conf=1
- elif [ "$word" == "--decoding-conf" ] ; then
- decoding_conf_found=1
- elif [ "$word" == "--encoding-conf" ] ; then
- encoding_conf_found=1
- elif [ "$word" == "--arithmetic-conf" ] ; then
- arithmetic_conf_found=1
- elif [ "$word" == "--sequence-conf" ] ; then
- sequence_conf_found=1
- elif [ "$word" == "--permutation-conf" ] ; then
- permutation_conf_found=1
- else
- do_not_suggest_conf=1
- fi
- fi
- elif [[ $word == -* ]]; then
- if [ "$examples_scripts_found" -eq 1 ] ; then
- if [ "$word" == "-rnd" ] ; then
- examples_scripts_rnd_found=1
- fi
- fi
- given_list_options+=("$word")
- elif [ "$word" == ">" ] || [ "$word" == ">>" ]; then
- option_with_w_path=1
- fi
- done
- len_given_list_command=${#given_list_command[@]}
- ####################################
- # get options for the last command #
- ####################################
- get_options=0
- options_tmp=()
- options=()
- for arg in ${all_possible_args[@]}; do
- if [[ $arg == $last_command ]]; then
- get_options=1
- elif [[ $arg == --* ]]; then
- get_options=0
- else
- if [ $get_options -eq 1 ] ;then
- options_tmp+=("$arg")
- fi
- fi
- done
- ## strip already seen elements from options
- len=${#options_tmp[@]}
- for (( i=0; i<$((len)); i++ )); do
- found=0
- for option in ${given_list_options[@]}; do
- if [ "${options_tmp[$i]}" == "$option" ]; then
- if [ "-add-decoy-binomial-key" != "$option" ]; then
- found=1
- fi
- if [ "-block-file" != "$option" ]; then
- found=1
- fi
- fi
- done
- if [ "$found" -eq 0 ]; then
- options+=("${options_tmp[$i]}")
- fi
- done
- #############
- # get paths #
- #############
- option_with_r_path=0
- for arg in ${options_followed_by_r_path[@]}; do
- for option in ${options_tmp[@]}; do
- if [ "$option" == "$arg" ] ; then
- if [ "${COMP_WORDS[-2]}" == "$arg" ] || [ "${COMP_WORDS[-1]}" == "$arg" ]; then
- option_with_r_path=1
- fi
- fi
- done
- done
- if [ "$option_with_r_path" -eq 1 ]; then
- if [ "${COMP_WORDS[-1]}" == "" ]; then
- possible_paths="$( ls . 2>/dev/null | tr -s '\n' ' ' )"
- else
- possible_paths="$( ls ${COMP_WORDS[-1]}* 2>/dev/null | tr -s '\n' ' ' )"
- fi
- else
- possible_paths=""
- fi
- for arg in ${options_followed_by_w_path[@]}; do
- if [ "$COMP_CWORD" -ge 2 ]; then
- if [ "${COMP_WORDS[-2]}" == "$arg" ]; then
- if [ "$option_with_r_path" -eq 0 ]; then
- option_with_w_path=1
- fi
- fi
- fi
- done
- ###############################
- # check if a space is reqired #
- ###############################
- add_space=0
- for arg in ${all_possible_args[@]}; do
- if [ "${COMP_WORDS[-1]}" == "$arg" ]; then
- add_space=1
- fi
- done
- ###############################
- # get possible commands lists #
- ###############################
- str_to_eval="possible_commands=\$(echo \" $tree_of_commands \" | tr -s '+' '\n' "
- if [ "$do_not_suggest_conf" -eq 1 ] ; then
- 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 "
- 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
- str_to_eval="$str_to_eval | grep -ve --decoding-conf | grep -ve --encoding-conf | grep -ve --arithmetic-conf | grep -ve --sequence-conf "
- elif [ "$sequence_conf_found" -eq 1 ] && [ "$encoding_conf_found" -eq 0 ] && [ "$decoding_conf_found" -eq 0 ] && [ "$arithmetic_conf_found" -eq 0 ] ; then
- str_to_eval="$str_to_eval | grep -ve --decoding-conf | grep -ve --encoding-conf | grep -ve --arithmetic-conf "
- elif [ "$arithmetic_conf_found" -eq 1 ] && [ "$encoding_conf_found" -eq 0 ] && [ "$decoding_conf_found" -eq 0 ] ; then
- str_to_eval="$str_to_eval | grep -ve --encoding-conf | grep -ve --decoding-conf "
- elif [ "$encoding_conf_found" -eq 1 ] && [ "$decoding_conf_found" -eq 0 ] ; then
- str_to_eval="$str_to_eval | grep -ve --decoding-conf "
- fi
- for command in ${given_list_command[@]}; do
- str_to_eval="$str_to_eval | grep -e $command "
- done
- str_to_eval="$str_to_eval | tr -s ' ' '\n' | sort | uniq "
- for command in ${given_list_command[@]}; do
- str_to_eval="$str_to_eval | grep -ve $command "
- done
- str_to_eval="$str_to_eval | tr -s '\n' ' ' )"
- eval "$str_to_eval"
- if [ "$permutation_conf_found" -eq 1 ] ; then
- 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')"
- elif [ "$sequence_conf_found" -eq 1 ] ; then
- str_to_eval="possible_commands=\$(echo ${possible_commands[@]} | sed 's/--decoding-conf//g' | sed 's/--encoding-conf//g' | sed 's/--arithmetic-conf//g')"
- eval "$str_to_eval"
- elif [ "$arithmetic_conf_found" -eq 1 ] ; then
- str_to_eval="possible_commands=\$(echo ${possible_commands[@]} | sed 's/--decoding-conf//g' | sed 's/--encoding-conf//g')"
- eval "$str_to_eval"
- elif [ "$encoding_conf_found" -eq 1 ] ; then
- str_to_eval="possible_commands=\$(echo ${possible_commands[@]} | sed 's/--decoding-conf//g')"
- eval "$str_to_eval"
- fi
- #############################
- # sort options and commands #
- #############################
- sorted_possible_first_commands=($(echo "${possible_first_commands[*]}" | tr ' ' '\n' | sort))
- sorted_list_strip_commands=($(echo "${list_strip_commands[*]}" | tr ' ' '\n' | sort))
- sorted_possible_commands=($(echo "${possible_commands[*]}" | tr ' ' '\n' | sort))
- sorted_options=($(echo "${options[*]}" | tr ' ' '\n' | sort))
- ############################
- # get possible suggestions #
- ############################
- possible_suggestions=""
- if [ "$option_with_r_path" -eq 1 ]; then
- possible_suggestions="$possible_paths"
- elif [ "$option_with_w_path" -eq 1 ]; then
- possible_suggestions=""
- elif [ "$help_found" -eq 1 ] && [ "$COMP_CWORD" -le 6 ] ; then
- possible_suggestions="${sorted_list_strip_commands[@]}"
- elif [ "$examples_scripts_found" -eq 1 ] && [ "$examples_scripts_rnd_found" -eq 0 ] && [ "$COMP_CWORD" -le 6 ] ; then
- possible_suggestions="-rnd "
- possible_suggestions="$possible_suggestions ${sorted_list_strip_commands[@]}"
- elif [ "$examples_scripts_found" -eq 1 ] && [ "$examples_scripts_rnd_found" -eq 1 ] && [ "$COMP_CWORD" -le 7 ] ; then
- possible_suggestions="${sorted_list_strip_commands[@]}"
- elif [ "$version_found" -eq 1 ] ; then
- possible_suggestions=""
- elif [ "$examples_scripts_found" -eq 0 ] && [ "$examples_scripts_found" -eq 0 ] && [ "$version_found" -eq 0 ] && [ "$COMP_CWORD" -le 1 ]; then
- possible_suggestions="${sorted_possible_first_commands[@]}"
- elif [ "$examples_scripts_found" -eq 0 ] && [ "$examples_scripts_found" -eq 0 ] && [ "$version_found" -eq 0 ] ; then
- possible_suggestions="${sorted_options[@]}"
- possible_suggestions="$possible_suggestions ${sorted_possible_commands[@]}"
- fi
- possible_suggestions="$possible_suggestions dummy"
- possible_suggestions_list=()
- while read -r -d ' ' element; do
- if [ -n "$element" ]; then
- possible_suggestions_list+=("$element")
- fi
- done <<< "$possible_suggestions"
- ##############################################################
- # check if the last work written completely matches one word #
- ##############################################################
- complete_matcth=0
- if [ "${COMP_WORDS[-1]}" == "-rnd" ]; then
- complete_matcth=1
- fi
- for arg in ${all_possible_args[@]}; do
- if [ "${COMP_WORDS[-1]}" == "$arg" ]; then
- complete_matcth=1
- fi
- done
- ###################
- # get suggestions #
- ###################
- COMPREPLY=()
- if [ "$add_space" -eq 1 ]; then
- COMPREPLY+=("${COMP_WORDS[-1]}")
- elif [ "$option_with_r_path" -eq 1 ]; then
- for suggestion in "${possible_suggestions_list[@]}"; do
- COMPREPLY+=("$suggestion")
- done
- elif [ "$option_with_w_path" -eq 1 ]; then
- COMPREPLY=()
- elif [ "$complete_matcth" -eq 0 ] ; then
- if [[ "-rnd" == *"${COMP_WORDS[-1]}"* ]] && [ "$examples_scripts_found" -eq 1 ] && [ "$examples_scripts_rnd_found" -eq 0 ]; then
- COMPREPLY+=("-rnd")
- fi
- for suggestion in "${possible_suggestions_list[@]}"; do
- if [[ "$suggestion" == "${COMP_WORDS[-1]}"* ]]; then
- COMPREPLY+=("$suggestion")
- fi
- done
- else
- for suggestion in "${possible_suggestions_list[@]}"; do
- COMPREPLY+=("$suggestion")
- done
- fi
- #echo "COMPREPLY ${COMPREPLY[@]}"
- }
- complete -o nosort -F _xrnlib_completitions xrnlib-cli
- #_xrnlib_completitions
|