#!/usr/bin/env bash R3_INSTALL_PATH=/usr/share/cybafelo/r3/r3-cloud R3_SRC_FOLDER="${R3_INSTALL_PATH}/r3-libs/r3-v2/src/r3/" R3_V2_FOLDER="${R3_INSTALL_PATH}/r3-libs/r3-v2/" r3_completions() { # TASK=${#COMP_WORDS[1]} if [ "${#COMP_WORDS[@]}" == "2" ]; then COMPREPLY=($(compgen -W "build-dist create build-events update-options update-templates update-methods update-token-db" "${COMP_WORDS[1]}")) fi if [[ "${#COMP_WORDS[@]}" == "3" && ( "${COMP_WORDS[1]}" == "update-templates" || "${COMP_WORDS[1]}" == "update-options" || "${COMP_WORDS[1]}" == "update-methods" ) ]]; then COMPREPLY=($(compgen -W "$(grep "r3 create" "${R3_V2_FOLDER}.r3_history" | sed "s/^.*r3 /r3 /" | sed "s/\s+/ /g" | sort --unique | cut -d' ' -f3 | sed 's/\([A-Z]\)/-\1/g' | awk '{print tolower($0)}' | sed "s/^/r3/" | sed "s/^r3\-r3/r3/" | sed "s/$/.js/" | perl -pe "s/\n/ /")" "${COMP_WORDS[2]}")) fi if [[ "${#COMP_WORDS[@]}" == "3" && ( "${COMP_WORDS[1]}" == "create" ) ]]; then COMPREPLY=($(compgen -W "Component Entity System Runtime" "${COMP_WORDS[2]}")) && compopt -o nospace fi if [ "${#COMP_WORDS[@]}" == "4" ]; then COMPREPLY=($(compgen -W "base extends object_base object_extends component_base component_extends entity_base entity_extends r3_base runtime_base runtime_extends system_base system_extends static" "${COMP_WORDS[3]}")) fi if [ "${#COMP_WORDS[@]}" == "5" ] && [ "${COMP_WORDS[3]}" == "component_extends" ] ; then local classes=$(grep "^class" "${R3_INSTALL_PATH}"/r3-libs/r3-v2/src/r3/r3-component/*.js | perl -pe "s/.*class\s*(\w.*?)\s.*/\1/" | perl -pe 's/\n/ /g') COMPREPLY=($(compgen -W "${classes}" "${COMP_WORDS[4]}")) fi if [ "${#COMP_WORDS[@]}" == "5" ] && [ "${COMP_WORDS[3]}" == "object_extends" ] ; then local classes=$(grep "^class" "${R3_INSTALL_PATH}"/r3-libs/r3-v2/src/r3/r3-r3-object.js | perl -pe "s/.*class\s*(\w.*?)\s.*/\1/" | perl -pe 's/\n/ /g') COMPREPLY=($(compgen -W "${classes}" "${COMP_WORDS[4]}")) fi if [ "${#COMP_WORDS[@]}" == "5" ] && [ "${COMP_WORDS[3]}" == "entity_extends" ] ; then local classes=$(grep "^class" "${R3_INSTALL_PATH}"/r3-libs/r3-v2/src/r3/r3-entity/*.js | perl -pe "s/.*class\s*(\w.*?)\s.*/\1/" | perl -pe 's/\n/ /g') COMPREPLY=($(compgen -W "${classes}" "${COMP_WORDS[4]}")) fi if [ "${#COMP_WORDS[@]}" == "5" ] && [ "${COMP_WORDS[3]}" == "runtime_extends" ] ; then local classes=$(grep "^class" "${R3_INSTALL_PATH}"/r3-libs/r3-v2/src/r3/r3-runtime/*.js | perl -pe "s/.*class\s*(\w.*?)\s.*/\1/" | perl -pe 's/\n/ /g') COMPREPLY=($(compgen -W "${classes}" "${COMP_WORDS[4]}")) fi if [ "${#COMP_WORDS[@]}" == "5" ] && [ "${COMP_WORDS[3]}" == "system_extends" ] ; then local classes=$(grep "^class" "${R3_INSTALL_PATH}"/r3-libs/r3-v2/src/r3/r3-system/*.js | perl -pe "s/.*class\s*(\w.*?)\s.*/\1/" | perl -pe 's/\n/ /g') COMPREPLY=($(compgen -W "${classes}" "${COMP_WORDS[4]}")) fi if [ "${#COMP_WORDS[@]}" == "5" ] && [ "${COMP_WORDS[3]}" == "extends" ] ; then local classes=$(grep "^class" "${R3_INSTALL_PATH}"/r3-libs/r3-v2/src/r3/*.js | perl -pe "s/.*class\s*(\w.*?)\s.*/\1/" | perl -pe 's/\n/ /g') COMPREPLY=($(compgen -W "${classes}" "${COMP_WORDS[4]}")) fi if [ "${#COMP_WORDS[@]}" == "5" ] && [ "${COMP_WORDS[3]}" == "system" ] ; then local classes=$(grep "^class" "${R3_INSTALL_PATH}"/r3-libs/r3-v2/src/r3/r3-system/*.js | perl -pe "s/.*class\s*(\w.*?)\s.*/\1/" | perl -pe 's/\n/ /g') COMPREPLY=($(compgen -W "${classes}" "${COMP_WORDS[4]}")) fi if [[ "${#COMP_WORDS[@]}" == "5" && ( "${COMP_WORDS[3]}" =~ ^.*base$ || "${COMP_WORDS[3]}" == "static") ]]; then COMPREPLY=($(compgen -W "$(find "${R3_SRC_FOLDER}" -ls | grep drw | sed "s/.*src\/r3/./" | sed "s/$/\//" | sed "s/\/\//\//g" | perl -pe 's/\n/ /g')" "${COMP_WORDS[4]}")) fi if [[ "${#COMP_WORDS[@]}" == "6" && ( "${COMP_WORDS[3]}" =~ ^.*extends$ ) ]]; then COMPREPLY=($(compgen -W "$(find "${R3_SRC_FOLDER}" -ls | grep drw | sed "s/.*src\/r3/./" | sed "s/$/\//" | sed "s/\/\//\//g" | perl -pe 's/\n/ /g')" "${COMP_WORDS[5]}")) fi if [[ "${#COMP_WORDS[@]}" == "7" && ( "${COMP_WORDS[3]}" =~ ^.*component_extends$ ) ]]; then COMPREPLY=($(compgen -W "$(cat "${R3_SRC_FOLDER}"r3-runtime/* | grep "extends Runtime\b" | cut -d " " -f 2 | perl -pe 's/\n/ /g')" "${COMP_WORDS[6]}")) fi } complete -F r3_completions r3