bash-completion.sh
branchv_0
changeset 37 3de41719d7eb
parent 34 24c05e69d68f
child 47 428c278af4be
equal deleted inserted replaced
36:91cb012d779a 37:3de41719d7eb
    11 # GNU General Public License for more details.
    11 # GNU General Public License for more details.
    12 #
    12 #
    13 # You should have received a copy of the GNU General Public License
    13 # You should have received a copy of the GNU General Public License
    14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
    14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
    15 
    15 
       
    16 _relpipe_tr_sql_completion_dsn() {
       
    17 	if type relpipe-out-nullbyte &> /dev/null; then
       
    18 		relpipe-tr-sql --list-data-sources | relpipe-out-nullbyte | while read -r -d '' name; do read -r -d '' description; echo $name; done
       
    19 	fi
       
    20 }
       
    21 
    16 _relpipe_tr_sql_completion() {
    22 _relpipe_tr_sql_completion() {
    17 	local w0 w1 w2
    23 	local w0 w1 w2
    18 
    24 
    19 	COMPREPLY=()
    25 	COMPREPLY=()
    20 	w0=${COMP_WORDS[COMP_CWORD]}
    26 	w0=${COMP_WORDS[COMP_CWORD]}
    25 		"string"
    31 		"string"
    26 		"integer"
    32 		"integer"
    27 		"boolean"
    33 		"boolean"
    28 	)
    34 	)
    29 
    35 
       
    36 	DATA_SOURCE_URL=(
       
    37 		"Driver=SQLite3;Database=file::memory:"
       
    38 		"Driver=SQLite3;Database=file:temp-relpipe.sqlite"
       
    39 		"Driver=SQLite3;Database=file:/tmp/relpipe.sqlite"
       
    40 	)
       
    41 
    30 	if   [[ "$w1" == "--relation"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
    42 	if   [[ "$w1" == "--relation"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
    31 	elif [[ "$w2" == "--relation"      && "x$w0" == "x" ]];    then COMPREPLY=('"SELECT * FROM "')
    43 	elif [[ "$w2" == "--relation"      && "x$w0" == "x" ]];    then COMPREPLY=('"SELECT * FROM "')
    32 	elif [[ "$w1" == "--type-cast"     && "x$w0" == "x" ]];    then COMPREPLY=("''")
    44 	elif [[ "$w1" == "--type-cast"     && "x$w0" == "x" ]];    then COMPREPLY=("''")
    33 	elif [[ "$w2" == "--type-cast"                      ]];    then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0"))
    45 	elif [[ "$w2" == "--type-cast"                      ]];    then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0"))
    34 	elif [[ "$w1" == "--parameter"     && "x$w0" == "x" ]];    then COMPREPLY=("''")
    46 	elif [[ "$w1" == "--parameter"     && "x$w0" == "x" ]];    then COMPREPLY=("''")
    35 	elif [[ "$w1" == "--copy"          && "x$w0" == "x" ]];    then COMPREPLY=("'.+'")
    47 	elif [[ "$w1" == "--copy"          && "x$w0" == "x" ]];    then COMPREPLY=("'.+'")
    36 	elif [[ "$w1" == "--copy-renamed"  && "x$w0" == "x" ]];    then COMPREPLY=("'.+'")
    48 	elif [[ "$w1" == "--copy-renamed"  && "x$w0" == "x" ]];    then COMPREPLY=("'.+'")
    37 	elif [[ "$w2" == "--copy-renamed"  && "x$w0" == "x" ]];    then COMPREPLY=("'copy_of_\$0'")
    49 	elif [[ "$w2" == "--copy-renamed"  && "x$w0" == "x" ]];    then COMPREPLY=("'copy_of_\$0'")
    38 	elif [[ "$w1" == "--file"                           ]];    then COMPREPLY=($(compgen -f "$w0"))
    50 	elif [[ "$w1" == "--data-source-name"               ]];    then COMPREPLY=($(compgen -W "$(_relpipe_tr_sql_completion_dsn)" -- "$w0"))
    39 	elif [[ "$w1" == "--file-keep"                      ]];    then COMPREPLY=($(compgen -W "true false auto" -- "$w0"))
    51 	elif [[ "$w1" == "--data-source-url"                ]];    then COMPREPLY=($(compgen -W "${DATA_SOURCE_URL[*]}" -- "$w0"))
    40 	else
    52 	else
    41 		OPTIONS=(
    53 		OPTIONS=(
    42 			"--relation"
    54 			"--relation"
    43 			"--type-cast"
    55 			"--type-cast"
    44 			"--parameter"
    56 			"--parameter"
    45 			"--copy"
    57 			"--copy"
    46 			"--copy-renamed"
    58 			"--copy-renamed"
    47 			"--file"
       
    48 			"--file-keep"
       
    49 			"--list-data-sources"
    59 			"--list-data-sources"
       
    60 			"--data-source-name"
       
    61 			"--data-source-url"
    50 		)
    62 		)
    51 		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
    63 		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
    52 	fi
    64 	fi
    53 }
    65 }
    54 
    66