2021-03-18 07:14:13 +00:00
|
|
|
#
|
|
|
|
# bash autocomplete, that can work with:
|
|
|
|
# a) --help of program
|
|
|
|
#
|
|
|
|
# Also you may like:
|
|
|
|
# $ bind "set completion-ignore-case on"
|
|
|
|
# $ bind "set show-all-if-ambiguous on"
|
|
|
|
#
|
|
|
|
# It uses bash-completion dynamic loader.
|
|
|
|
|
|
|
|
# Known to work with bash 3.* with programmable completion and extended
|
|
|
|
# pattern matching enabled (use 'shopt -s extglob progcomp' to enable
|
|
|
|
# these if they are not already enabled).
|
|
|
|
shopt -s extglob
|
|
|
|
|
|
|
|
export _CLICKHOUSE_COMPLETION_LOADED=1
|
|
|
|
|
2022-04-24 19:36:27 +00:00
|
|
|
CLICKHOUSE_logs_level=(
|
|
|
|
none
|
|
|
|
fatal
|
|
|
|
error
|
|
|
|
warning
|
|
|
|
information
|
|
|
|
debug
|
|
|
|
trace
|
|
|
|
test
|
|
|
|
)
|
|
|
|
|
2021-05-04 19:23:08 +00:00
|
|
|
CLICKHOUSE_QueryProcessingStage=(
|
|
|
|
complete
|
|
|
|
fetch_columns
|
|
|
|
with_mergeable_state
|
|
|
|
with_mergeable_state_after_aggregation
|
2021-06-04 06:43:56 +00:00
|
|
|
with_mergeable_state_after_aggregation_and_limit
|
2021-05-04 19:23:08 +00:00
|
|
|
)
|
|
|
|
|
2022-05-17 11:48:06 +00:00
|
|
|
CLICKHOUSE_QueryKind=(
|
|
|
|
initial_query
|
|
|
|
secondary_query
|
|
|
|
no_query
|
|
|
|
)
|
|
|
|
|
2022-08-28 15:21:49 +00:00
|
|
|
# SELECT name FROM system.formats ORDER BY name FORMAT LineAsString
|
2021-05-12 18:11:36 +00:00
|
|
|
CLICKHOUSE_Format=(
|
|
|
|
Arrow
|
2022-08-28 15:21:49 +00:00
|
|
|
ArrowStream
|
|
|
|
Avro
|
2021-05-12 18:11:36 +00:00
|
|
|
AvroConfluent
|
2023-10-26 15:34:47 +00:00
|
|
|
BSONEachRow
|
2022-08-28 15:21:49 +00:00
|
|
|
CSV
|
|
|
|
CSVWithNames
|
|
|
|
CSVWithNamesAndTypes
|
|
|
|
CapnProto
|
2021-05-12 18:11:36 +00:00
|
|
|
CustomSeparated
|
2022-08-28 15:21:49 +00:00
|
|
|
CustomSeparatedIgnoreSpaces
|
|
|
|
CustomSeparatedIgnoreSpacesWithNames
|
|
|
|
CustomSeparatedIgnoreSpacesWithNamesAndTypes
|
|
|
|
CustomSeparatedWithNames
|
|
|
|
CustomSeparatedWithNamesAndTypes
|
2023-10-26 15:34:47 +00:00
|
|
|
DWARF
|
2022-08-28 15:21:49 +00:00
|
|
|
HiveText
|
|
|
|
JSON
|
|
|
|
JSONAsObject
|
|
|
|
JSONAsString
|
|
|
|
JSONColumns
|
|
|
|
JSONColumnsWithMetadata
|
|
|
|
JSONCompact
|
|
|
|
JSONCompactColumns
|
|
|
|
JSONCompactEachRow
|
|
|
|
JSONCompactEachRowWithNames
|
|
|
|
JSONCompactEachRowWithNamesAndTypes
|
|
|
|
JSONCompactStrings
|
|
|
|
JSONCompactStringsEachRow
|
|
|
|
JSONCompactStringsEachRowWithNames
|
2021-05-12 18:11:36 +00:00
|
|
|
JSONCompactStringsEachRowWithNamesAndTypes
|
2022-08-28 15:21:49 +00:00
|
|
|
JSONEachRow
|
|
|
|
JSONEachRowWithProgress
|
|
|
|
JSONLines
|
2023-10-26 15:34:47 +00:00
|
|
|
JSONObjectEachRow
|
2022-08-28 15:21:49 +00:00
|
|
|
JSONStrings
|
2021-05-12 18:11:36 +00:00
|
|
|
JSONStringsEachRow
|
2022-08-28 15:21:49 +00:00
|
|
|
JSONStringsEachRowWithProgress
|
2021-05-12 18:11:36 +00:00
|
|
|
LineAsString
|
2022-08-28 15:21:49 +00:00
|
|
|
LineAsStringWithNames
|
|
|
|
LineAsStringWithNamesAndTypes
|
|
|
|
Markdown
|
|
|
|
MsgPack
|
|
|
|
MySQLDump
|
|
|
|
MySQLWire
|
|
|
|
NDJSON
|
2021-05-12 18:11:36 +00:00
|
|
|
Native
|
2022-08-28 15:21:49 +00:00
|
|
|
Null
|
|
|
|
ODBCDriver2
|
|
|
|
ORC
|
2023-10-26 15:34:47 +00:00
|
|
|
One
|
2022-08-28 15:21:49 +00:00
|
|
|
Parquet
|
2023-10-26 15:34:47 +00:00
|
|
|
ParquetMetadata
|
2022-08-28 15:21:49 +00:00
|
|
|
PostgreSQLWire
|
|
|
|
Pretty
|
|
|
|
PrettyCompact
|
|
|
|
PrettyCompactMonoBlock
|
|
|
|
PrettyCompactNoEscapes
|
|
|
|
PrettyCompactNoEscapesMonoBlock
|
2023-10-26 15:34:47 +00:00
|
|
|
PrettyJSONEachRow
|
|
|
|
PrettyJSONLines
|
2022-08-28 15:21:49 +00:00
|
|
|
PrettyMonoBlock
|
2023-10-26 15:34:47 +00:00
|
|
|
PrettyNDJSON
|
2022-08-28 15:21:49 +00:00
|
|
|
PrettyNoEscapes
|
|
|
|
PrettyNoEscapesMonoBlock
|
2021-05-12 18:11:36 +00:00
|
|
|
PrettySpace
|
2022-08-28 15:21:49 +00:00
|
|
|
PrettySpaceMonoBlock
|
|
|
|
PrettySpaceNoEscapes
|
|
|
|
PrettySpaceNoEscapesMonoBlock
|
|
|
|
Prometheus
|
|
|
|
Protobuf
|
|
|
|
ProtobufList
|
|
|
|
ProtobufSingle
|
|
|
|
RawBLOB
|
2021-05-12 18:11:36 +00:00
|
|
|
Regexp
|
2022-08-28 15:21:49 +00:00
|
|
|
RowBinary
|
2023-10-26 15:34:47 +00:00
|
|
|
RowBinaryWithDefaults
|
2022-08-28 15:21:49 +00:00
|
|
|
RowBinaryWithNames
|
|
|
|
RowBinaryWithNamesAndTypes
|
|
|
|
SQLInsert
|
|
|
|
TSKV
|
2021-05-12 18:11:36 +00:00
|
|
|
TSV
|
2022-08-28 15:21:49 +00:00
|
|
|
TSVRaw
|
|
|
|
TSVRawWithNames
|
|
|
|
TSVRawWithNamesAndTypes
|
2021-05-12 18:11:36 +00:00
|
|
|
TSVWithNames
|
2022-08-28 15:21:49 +00:00
|
|
|
TSVWithNamesAndTypes
|
|
|
|
TabSeparated
|
|
|
|
TabSeparatedRaw
|
|
|
|
TabSeparatedRawWithNames
|
|
|
|
TabSeparatedRawWithNamesAndTypes
|
|
|
|
TabSeparatedWithNames
|
|
|
|
TabSeparatedWithNamesAndTypes
|
|
|
|
Template
|
|
|
|
TemplateIgnoreSpaces
|
|
|
|
Values
|
|
|
|
Vertical
|
|
|
|
XML
|
2021-05-12 18:11:36 +00:00
|
|
|
)
|
|
|
|
|
2021-03-18 07:14:13 +00:00
|
|
|
function _clickhouse_bin_exist()
|
|
|
|
{ [ -x "$1" ] || command -v "$1" >& /dev/null; }
|
|
|
|
|
|
|
|
function _clickhouse_quote()
|
|
|
|
{
|
|
|
|
local quoted=${1//\'/\'\\\'\'};
|
|
|
|
printf "'%s'" "$quoted"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Extract every option (everything that starts with "-") from the --help dialog.
|
|
|
|
function _clickhouse_get_options()
|
|
|
|
{
|
2024-05-28 16:02:29 +00:00
|
|
|
# By default --help will not print all settings, this is done only under --verbose
|
2024-10-06 19:43:53 +00:00
|
|
|
"$@" --help --verbose 2>&1 | LANG=c awk -F '[ ,=<>.]' '{ for (i=1; i <= NF; ++i) { if (substr($i, 1, 1) == "-" && length($i) > 1) print $i; } }' | sort -u
|
2021-03-18 07:14:13 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 19:23:08 +00:00
|
|
|
function _complete_for_clickhouse_generic_bin_impl()
|
2021-03-18 07:14:13 +00:00
|
|
|
{
|
2021-05-04 19:23:08 +00:00
|
|
|
local prev=$1 && shift
|
2021-03-18 07:14:13 +00:00
|
|
|
|
|
|
|
case "$prev" in
|
|
|
|
-C|--config-file|--config)
|
2021-05-04 19:23:08 +00:00
|
|
|
return 1
|
2021-03-18 07:14:13 +00:00
|
|
|
;;
|
2021-05-04 19:23:08 +00:00
|
|
|
--stage)
|
|
|
|
COMPREPLY=( $(compgen -W "${CLICKHOUSE_QueryProcessingStage[*]}" -- "$cur") )
|
|
|
|
return 1
|
|
|
|
;;
|
2022-05-17 11:48:06 +00:00
|
|
|
--query_kind)
|
|
|
|
COMPREPLY=( $(compgen -W "${CLICKHOUSE_QueryKind[*]}" -- "$cur") )
|
|
|
|
return 1
|
|
|
|
;;
|
2022-04-24 19:36:27 +00:00
|
|
|
--send_logs_level)
|
|
|
|
COMPREPLY=( $(compgen -W "${CLICKHOUSE_logs_level[*]}" -- "$cur") )
|
|
|
|
return 1
|
|
|
|
;;
|
2021-05-12 18:11:36 +00:00
|
|
|
--format|--input-format|--output-format)
|
|
|
|
COMPREPLY=( $(compgen -W "${CLICKHOUSE_Format[*]}" -- "$cur") )
|
|
|
|
return 1
|
|
|
|
;;
|
2021-05-04 19:23:08 +00:00
|
|
|
--host)
|
|
|
|
COMPREPLY=( $(compgen -A hostname -- "$cur") )
|
|
|
|
return 1
|
|
|
|
;;
|
2021-03-18 07:14:13 +00:00
|
|
|
# Argh... This looks like a bash bug...
|
|
|
|
# Redirections are passed to the completion function
|
|
|
|
# although it is managed by the shell directly...
|
|
|
|
'<'|'>'|'>>'|[12]'>'|[12]'>>')
|
2021-05-04 19:23:08 +00:00
|
|
|
return 1
|
2021-03-18 07:14:13 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2021-05-04 19:23:08 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function _complete_for_clickhouse_generic_bin()
|
|
|
|
{
|
|
|
|
local cur prev
|
|
|
|
eval local cmd="$( _clickhouse_quote "$1" )"
|
|
|
|
_clickhouse_bin_exist "$cmd" || return 0
|
|
|
|
|
|
|
|
COMPREPLY=()
|
|
|
|
_get_comp_words_by_ref cur prev
|
|
|
|
|
|
|
|
if _complete_for_clickhouse_generic_bin_impl "$prev"; then
|
|
|
|
COMPREPLY=( $(compgen -W "$(_clickhouse_get_options "$cmd")" -- "$cur") )
|
|
|
|
fi
|
2021-03-18 07:14:13 +00:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function _complete_clickhouse_generic()
|
|
|
|
{
|
|
|
|
local bin=$1 && shift
|
|
|
|
local f=${1:-_complete_for_clickhouse_generic_bin}
|
|
|
|
local o=(
|
|
|
|
-o default
|
|
|
|
-o bashdefault
|
|
|
|
-o nospace
|
|
|
|
-F "$f"
|
|
|
|
"$bin"
|
|
|
|
)
|
|
|
|
complete "${o[@]}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function _complete_clickhouse_bootstrap_main()
|
|
|
|
{
|
|
|
|
local runtime=/usr/share/bash-completion/bash_completion
|
|
|
|
if ! type _get_comp_words_by_ref >& /dev/null && [[ -f $runtime ]]; then
|
|
|
|
source $runtime
|
|
|
|
fi
|
|
|
|
type _get_comp_words_by_ref >& /dev/null || return 0
|
|
|
|
}
|
|
|
|
_complete_clickhouse_bootstrap_main "$@"
|