1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- _xrnserver-cli_autocomplete() {
- local cur prev opts
- COMPREPLY=()
- cur="${COMP_WORDS[COMP_CWORD]}"
- #prev="${COMP_WORDS[COMP_CWORD-1]}"
- command=$( echo "${COMP_WORDS[@]}" | tr -s ' ' '\n' | awk '/--/{print $0}' )
- opts_start_server="-input-tar -cache-dir -output-tar -input-log-json -output-log-json"
- # Convert space-separated strings to arrays
- read -r -a array0 <<< "$opts_start_server"
- read -r -a array1 <<< "${COMP_WORDS[@]}"
- # Initialize an empty array to store the result
- result=()
- # Loop over each element in the first array
- for item in "${array0[@]}"; do
- # Check if the element exists in the second array
- if [[ ! " ${array1[@]} " =~ " $item " ]]; then
- # Add the element to the result array
- result+=("$item")
- fi
- done
- opts_start_server_sub="${result[*]}"
- # Check if an option has already been used
- local used_opts=$(echo "${COMP_WORDS[@]}" | grep -oE -- '(\s|^)--[a-zA-Z0-9]+' | sort | uniq)
- case "${command}" in
- --start-server)
- COMPREPLY=( $(compgen -W "${opts_start_server_sub}" -- ${cur}) )
- return 0
- ;;
- *)
- COMPREPLY=( $(compgen -W "--start-server $(echo "${opts}" | grep -v -E "${used_opts}")" -- ${cur}) )
- return 0
- ;;
- esac
- }
- complete -F _xrnserver-cli_autocomplete xrnserver-cli
|