diff options
Diffstat (limited to 'src/bash_completion')
-rw-r--r-- | src/bash_completion/CMakeLists.txt | 15 | ||||
-rw-r--r-- | src/bash_completion/ceph | 50 | ||||
-rw-r--r-- | src/bash_completion/rados | 40 | ||||
-rw-r--r-- | src/bash_completion/radosgw-admin | 57 | ||||
-rw-r--r-- | src/bash_completion/rbd | 83 |
5 files changed, 245 insertions, 0 deletions
diff --git a/src/bash_completion/CMakeLists.txt b/src/bash_completion/CMakeLists.txt new file mode 100644 index 000000000..8d834774d --- /dev/null +++ b/src/bash_completion/CMakeLists.txt @@ -0,0 +1,15 @@ +set(completions + ceph + rados) + +if(WITH_RBD) + list(APPEND completions rbd) +endif() + +if(WITH_RADOSGW) + list(APPEND completions radosgw-admin) +endif() + +install(FILES ${completions} + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/bash_completion.d) + diff --git a/src/bash_completion/ceph b/src/bash_completion/ceph new file mode 100644 index 000000000..d28c8a4fa --- /dev/null +++ b/src/bash_completion/ceph @@ -0,0 +1,50 @@ +# +# Ceph - scalable distributed file system +# +# This is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software +# Foundation. +# + +_ceph() +{ + local options_noarg="-h --help -s --status -w --watch --watch-debug --watch-info --watch-sec --watch-warn --watch-error --version -v --verbose --concise" + local options_arg="-c --conf -i --in-file -o --out-file --id --user -n --name --cluster --admin-daemon --admin-socket -f --format --connect-timeout" + local cnt=${#COMP_WORDS[@]} + local cur=${COMP_WORDS[COMP_CWORD]} + local prev=${COMP_WORDS[COMP_CWORD-1]} + + if [[ " -c --conf -i --in-file -o --out-file " =~ " ${prev} " ]] + then + #default autocomplete for options (file autocomplete) + compopt -o default + COMPREPLY=() + return 0 + fi + if [[ "${cur:0:1}" == "-" ]] ; + then + COMPREPLY=( $(compgen -W "${options_noarg} ${options_arg}" -- $cur) ) + return 0 + fi + declare -a hint_args + for (( i=1 ; i<cnt ; i++ )) + do + #skip this word if it is option + if [[ " ${options_noarg} " =~ " ${COMP_WORDS[i]} " ]] + then + continue + fi + #skip this word and next if it is option with arg + if [[ " ${options_arg} " =~ " ${COMP_WORDS[i]} " ]] + then + ((i++)); + continue + fi + hint_args[$((i-1))]="${COMP_WORDS[i]}" + done + + local IFS=$'\n' + COMPREPLY=( $(${COMP_WORDS[0]} --completion "${hint_args[@]}" 2>/dev/null) ) +} +complete -F _ceph ceph diff --git a/src/bash_completion/rados b/src/bash_completion/rados new file mode 100644 index 000000000..63501875c --- /dev/null +++ b/src/bash_completion/rados @@ -0,0 +1,40 @@ +# +# Ceph - scalable distributed file system +# +# Copyright (C) 2011 Wido den Hollander <wido@widodh.nl> +# +# This is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software +# Foundation. See file COPYING. +# + +_rados() +{ + local cur prev + + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + if [[ ${cur} == -* ]] ; then + COMPREPLY=( $(compgen -W "-c --conf -m -d -f -p --pool -b --snap -i -o --create" -- ${cur}) ) + return 0 + fi + + case "${prev}" in + --conf | -c | -o | -i) + COMPREPLY=( $(compgen -f ${cur}) ) + return 0 + ;; + -m) + COMPREPLY=( $(compgen -A hostname ${cur}) ) + return 0 + ;; + rados) + COMPREPLY=( $(compgen -W "lspools df ls chown get put create rm listxattr getxattr setxattr rmxattr stat stat2 mapext lssnap mksnap rmsnap rollback bench" -- ${cur}) ) + return 0 + ;; + esac +} +complete -F _rados rados diff --git a/src/bash_completion/radosgw-admin b/src/bash_completion/radosgw-admin new file mode 100644 index 000000000..023a83f87 --- /dev/null +++ b/src/bash_completion/radosgw-admin @@ -0,0 +1,57 @@ +# +# Ceph - scalable distributed file system +# +# Copyright (C) 2011 Wido den Hollander <wido@widodh.nl> +# +# This is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software +# Foundation. See file COPYING. +# + +_radosgw_admin() +{ + local cur prev + + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + if [[ ${cur} == -* ]] ; then + COMPREPLY=( $(compgen -W "--uid --subuser --access-key --os-user --email --auth_uid --secret --os-secret --gen-access-key --gen-secret \ + --access --display-name --bucket --object --date --conf --name --id --version -s -w" -- ${cur}) ) + return 0 + fi + + case "${prev}" in + --conf | -c) + COMPREPLY=( $(compgen -f ${cur}) ) + return 0 + ;; + -m) + COMPREPLY=( $(compgen -A hostname ${cur}) ) + return 0 + ;; + user) + COMPREPLY=( $(compgen -W "create modify info rm" -- ${cur}) ) + return 0 + ;; + subuser) + COMPREPLY=( $(compgen -W "create modify rm" -- ${cur}) ) + return 0 + ;; + key) + COMPREPLY=( $(compgen -W "create rm" -- ${cur}) ) + return 0 + ;; + buckets) + COMPREPLY=( $(compgen -W "list unlink" -- ${cur}) ) + return 0 + ;; + *) + COMPREPLY=( $(compgen -W "user subuser key buckets policy log" -- ${cur}) ) + return 0 + ;; + esac +} +complete -F _radosgw_admin radosgw-admin diff --git a/src/bash_completion/rbd b/src/bash_completion/rbd new file mode 100644 index 000000000..bef1670e9 --- /dev/null +++ b/src/bash_completion/rbd @@ -0,0 +1,83 @@ +# +# Ceph - scalable distributed file system +# +# Copyright (C) 2011 Wido den Hollander <wido@widodh.nl> +# +# This is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software +# Foundation. See file COPYING. +# +_rbd_commands="" # lazy init +_rbd_global_options="" # lazy init + +_rbd() +{ + if [ "x${_rbd_commands}" == "x" ]; then + local rbc="$(rbd bash-completion 2>/dev/null)" + _rbd_commands="$(echo ${rbc} | sed -e 's/|-[^|]*//g' -e 's/||*/|/g')" + _rbd_global_options="$(echo ${rbc} | sed -e 's/|[^-][^\|]*//g' -e 's/||*/|/g')" + fi + + COMPREPLY=() + + local arg_count=${#COMP_WORDS[@]} + local args=() + local help_request="false" + for (( i=1; i<arg_count; i++ )); do + word="${COMP_WORDS[i]}" + if [[ "x${word}" == "xhelp" && ${#args} == 0 ]]; then + # treat help request as a special case + help_request="true" + continue + elif [[ $(echo ${_rbd_global_options} | grep "|${word}|") ]]; then + # skip flag option + continue + elif [[ "x${word:0:1}" == "x-" ]]; then + # skip option with argument + let i=$i+1 + continue + elif [[ "x${word}" == "x" ]]; then + # skip blank arguments + continue + fi + + args+=("${word}") + done + + local cur="${COMP_WORDS[COMP_CWORD]}" + local prev="${COMP_WORDS[COMP_CWORD-1]}" + + local options_exp=${_rbd_global_options} + local command="${args[@]}" + local valid_command="false" + if [[ ${#args} != 0 && "${args[-1]}" != "${cur}" && + $(echo "${_rbd_commands}" | grep -c "|${command}|") == 1 ]]; then + # combine global and command-specific options + local rbd_command_options="$(rbd bash-completion ${args[@]} 2>/dev/null)" + options_exp="${options_exp} ${rbd_command_options}" + valid_command="true" + fi + + if [[ "x${cur}" == "xhelp" ]]; then + COMPREPLY=() + elif [[ "${options_exp}}" =~ "|${prev} path|" ]]; then + # perform path completion for path argument + COMPREPLY=($(compgen -f ${cur})) + elif [[ "${options_exp}}" =~ "|${prev} host|" ]]; then + # perform host completion for host argument + COMPREPLY=($(compgen -A hostname ${cur})) + elif [[ "${help_request}" == "false" && ( "x${cur:0:1}" == "x-" || + ( "x${cur}" == "x" && "${valid_command}" == "true" ) ) ]]; then + # all valid options for current command + options="$(echo ${options_exp} | sed -e 's/||*/ /g' -r -e 's/ (arg|path|host)//g')" + COMPREPLY=($(compgen -W "${options}" -- ${cur})) + elif [[ "${valid_command}" == "false" ]]; then + # search for valid command + [[ "x${command}" != "x" && "x${cur}" == "x" ]] && command="${command} " + COMPREPLY=($(echo ${_rbd_commands} | grep -o "|${command}[^ |]*" | \ + uniq | sed -e 's/|//g' | awk -F' ' '{print $(NF)}')) + fi +} + +complete -F _rbd rbd |