-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add bash completion for memtier-benchmark
- Loading branch information
1 parent
891df95
commit 57c8fdc
Showing
4 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ m4 | |
Makefile.in | ||
missing | ||
*.o | ||
memtier_benchmark | ||
/memtier_benchmark | ||
.deps | ||
Makefile | ||
config.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#/usr/bin/env bash | ||
|
||
_memtier_look_for_element () { | ||
local op prev="$1" cur="$2" | ||
shift | ||
shift | ||
|
||
for op; do | ||
if [[ "${op}" == "${prev}" ]];then | ||
echo "${op}" | ||
break | ||
elif [[ "${cur}" == ${op}=* ]]; then | ||
echo "${op}=" | ||
break | ||
fi | ||
done | ||
} | ||
|
||
_memtier_completions() | ||
{ | ||
options_no_comp=("--server" "--port" "--unix-socket" "--out-file" "--client-stats" "--run-count" "--clients"\ | ||
"--requests" "--threads" "--test-time" "--ratio" "--pipeline" "--data-size" "--data-offset"\ | ||
"--data-size-range" "--data-size-list" "--expiry-range" "--data-import" "--key-prefix"\ | ||
"--key-minimum" "--key-maximum" "--reconnect-interval" "--multi-key-get" "--authenticate"\ | ||
"--select-db" "--wait-ratio" "--num-slaves" "--wait-timeout" "--json-out-file" "--command"\ | ||
"-s" "-p" "-S" "-o" "-x" "-c" "-n" "-t" "-d" "-a") | ||
|
||
options_no_args=("--debug" "--show-config" "--hide-histogram" "--distinct-client-seed" "--randomize"\ | ||
"--random-data" "--data-verify" "--verify-only" "--generate-keys" "--key-stddev"\ | ||
"--key-median" "--no-expiry" "--cluster-mode" "--help" "--version"\ | ||
"-D" "-R" "-h" "-v") | ||
|
||
options_comp=("--protocol" "-P" "--key-pattern" "--data-size-pattern") | ||
|
||
all_options="${options_no_comp[@]} ${options_no_args[@]} ${options_comp[@]}" | ||
|
||
local cur | ||
local prev | ||
_get_comp_words_by_ref -n ${COMP_WORDBREAKS} cur prev | ||
|
||
# check if it's option without completion | ||
local option=$(_memtier_look_for_element "${prev}" "" "${options_no_comp[@]}") | ||
if [ -n "${option}" ]; then | ||
option="no completion" | ||
else | ||
# check if it's option with completion | ||
option=$(_memtier_look_for_element "${prev}" "${cur}" "${options_comp[@]}") | ||
fi | ||
|
||
case "${option}" in | ||
"no completion") | ||
return | ||
;; | ||
"--protocol=") | ||
cur=${cur#"--protocol="} | ||
;& | ||
"-P") | ||
;& | ||
"--protocol") | ||
all_options="redis memcache_text memcache_binary" | ||
;; | ||
"--data-size-pattern=") | ||
cur=${cur#"--data-size-pattern="} | ||
;& | ||
"--data-size-pattern") | ||
all_options="R S" | ||
;; | ||
"--key-pattern=") | ||
cur=${cur#"--key-pattern="} | ||
;& | ||
"--key-pattern") | ||
if [[ -z "${cur}" ]]; then | ||
COMPREPLY=( $( compgen -W "G R S P" ) ) | ||
else | ||
if [[ "${cur}" =~ (G|R|S|P):(G|R|S)$ ]]; then | ||
COMPREPLY="${COMP_WORDS[COMP_CWORD]} " | ||
elif [[ "${cur}" =~ (G|R|S|P):$ ]]; then | ||
COMPREPLY=( $( compgen -W "G R S" ) ) | ||
elif [[ "${cur}" =~ (G|R|S|P)$ ]]; then | ||
COMPREPLY="${cur}:" | ||
fi | ||
fi | ||
|
||
return | ||
;; | ||
*) | ||
;; | ||
esac | ||
|
||
COMPREPLY=( $( compgen -W "${all_options}" -- "${cur}" ) ) | ||
if [ -n "${COMPREPLY}" ];then | ||
COMPREPLY="${COMPREPLY} " | ||
fi | ||
|
||
return | ||
} | ||
|
||
complete -o nospace -F _memtier_completions memtier_benchmark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters