From 1fca2856b3366a47472df4cae78f77794cf1ce71 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Mon, 8 Apr 2013 13:25:16 +0400 Subject: Fix dynamic loading --- bash-completion/Makefile | 1 - bash-completion/addons/smf | 174 -------------------------- bash-completion/addons/svcadm | 175 ++++++++++++++++++++++++++ bash-completion/addons/zfs | 243 ++++++++++++++++++++++++++++++++++++ bash-completion/addons/zfsutils | 243 ------------------------------------ bash-completion/bash-completion.p5m | 10 +- 6 files changed, 425 insertions(+), 421 deletions(-) delete mode 100644 bash-completion/addons/smf create mode 100644 bash-completion/addons/svcadm create mode 100644 bash-completion/addons/zfs delete mode 100644 bash-completion/addons/zfsutils diff --git a/bash-completion/Makefile b/bash-completion/Makefile index 00e9b31..afd2be1 100644 --- a/bash-completion/Makefile +++ b/bash-completion/Makefile @@ -1,6 +1,5 @@ package ?= ips include /usr/share/cibs/rules/$(package).mk -include /usr/share/cibs/rules/git.mk include /usr/share/cibs/rules/autotools.mk include /usr/share/cibs/rules/archive.mk include /usr/share/cibs/rules/noarch.mk diff --git a/bash-completion/addons/smf b/bash-completion/addons/smf deleted file mode 100644 index 57ce673..0000000 --- a/bash-completion/addons/smf +++ /dev/null @@ -1,174 +0,0 @@ -# svcadm completion -*- shell-script -*- -# -# Copyright 2006 Yann Rouillard - -# -# svcadm accept any complete FMRI or abreviated FMRI -# - a complete FMRI is svc:/foo/bar/bar/baz -# - abbreviated FMRI are foo/bar/bar/baz, bar/bar/baz, bar/baz or baz -# -# The goal of this function is to be able to propose all alternatives, -# but to not clutter the interface with all completions, we will only -# cut every completion alternative at the next slash. -# -# For exemple, if the user types , we will propose for svc://foo/bar/bar/baz -# the following completion: foo/, bar/ and baz -# If the user types , we will propose: bar/ and baz -# If the user types , we will propose: bar/bar/ and bar/baz -# -# By default, the function proproses only abbreviated completions except if the user already -# began to type svc:. In that case we will propose only the complete FMRI beginning with the -# pattern -# -_smf_complete_fmri () -{ - local cur="$1" prefix="$2" - local cur_prefix fmri fmri_list="" - local exact_mode pattern - - if [[ "$cur" == $prefix* ]]; then - [[ "$cur" == $prefix ]] && cur+="/" - pattern="$cur*" - exact_mode=1 - else - pattern="$prefix*/$cur*" - fi - - cur_prefix="${cur%"${cur##*/}"}" - - for fmri in $(svcs -H -o FMRI "$pattern" 2>/dev/null); do - local fmri_part_list fmri_part - if [[ -z "$exact_mode" ]]; then - fmri=${fmri#$prefix/} - - # we generate all possibles abbrevations for the FMRI - # no need to have a generic loop as we will have a finite - # number of components - local OIFS="$IFS"; IFS="/"; set -- $fmri; IFS="$OIFS" - case $# in - 1) fmri_part_list=" $1";; - 2) fmri_part_list=" $2 $1/$2";; - 3) fmri_part_list=" $3 $2/$3 $1/$2/$3";; - 4) fmri_part_list=" $4 $3/$4 $2/$3/$4 $1/$2/$3/$4";; - esac - else - fmri_part_list="$fmri" - fi - - # Here we make sure the completions begins with the pattern and - # we cut them at the first slash - for fmri_part in $fmri_part_list; do - [[ "$fmri_part" == $cur* ]] || continue - local first_part=${fmri_part#$cur_prefix} - first_part=$cur_prefix${first_part%%/*} - [[ "$first_part" != "$fmri_part" ]] && first_part+="/" - fmri_list+=" $first_part" - done - done - - COMPREPLY=( $fmri_list ) - - # here we want to detect if there only one completion proposed and that - # it ends with a slash. That means the users will still have to complete - # after, so we gain him one tab keystroke by immediately proposing the - # next completion alternatives - local i=${#COMPREPLY[*]} - if [[ $i -gt 0 ]] && [[ "${COMPREPLY[$((--i))]}" == */ ]]; then - # we have to iterate throught the list as we may have duplicate - while [[ $i -ne 0 ]]; do - [[ "${COMPREPLY[$i]}" != "${COMPREPLY[$((i - 1))]}" ]] && break - ((i--)) - done - if [[ $i -eq 0 ]]; then - _smf_complete_fmri "${COMPREPLY[0]}" "$prefix" - return 0 - fi - fi - - # Work-around bash_completion issue where bash interprets a colon - # as a separator, borrowed from maven completion code which borrowed - # it from darcs completion code :) - local colonprefixes=${cur%"${cur##*:}"} - local i=${#COMPREPLY[*]} - while [ $((--i)) -ge 0 ]; do - COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"} - done -} - -_svcadm () -{ - local cur prev words cword - _init_completion -n : || return - - local command_list="enable disable restart refresh clear mark milestone" - local command i - - for (( i=1; i < $cword; i++ )); do - if [[ ${words[i]} == @(enable|disable|restart|refresh|clear|mark|milestone) ]]; then - command=${words[i]} - fi - done - - if [[ -z "$command" ]]; then - if [[ ${cur} == -* ]] ; then - COMPREPLY=( $(compgen -W "-v" -- ${cur}) ) - else - COMPREPLY=( $(compgen -W "$command_list" -- ${cur}) ) - fi - else - if [[ ${cur} == -* ]]; then - case "$command" in - enable) - COMPREPLY=( $(compgen -W "-r -s -t" -- ${cur}) );; - disable) - COMPREPLY=( $(compgen -W "-s -t" -- ${cur}) );; - mark) - COMPREPLY=( $(compgen -W "-I -t" -- ${cur}) );; - milestone) - COMPREPLY=( $(compgen -W "-d" -- ${cur}) );; - esac - else - if [[ "$command" == "mark" ]] && [[ "$prev" != @(degraded|maintenance) ]]; then - COMPREPLY=( $(compgen -W "degraded maintenance" -- ${cur}) ) - elif [[ "$command" == "milestone" ]]; then - _smf_complete_fmri "${cur}" "svc:/milestone" - else - _smf_complete_fmri "${cur}" "svc:" - fi - fi - fi -} && -complete -F _svcadm svcadm - - -_svcs () { - local cur prev opts line - local svcs_cols="ctid desc fmri inst nsta nstate scope svc sta state stime" - COMPREPLY=() - - cur=${COMP_WORDS[COMP_CWORD]} - prev="${COMP_WORDS[COMP_CWORD-1]}" - line="${COMP_LINE}" - - case "$prev" in - -o|-s|-S) - COMPREPLY=($(compgen -W "$svcs_cols" -- "${cur##*,}")) - local existing_opts=$(expr "$cur" : '\(.*,\)') - if [[ -n "$existing_opts" ]]; then - COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" ) - fi - compopt -o nospace - return;; - esac - - if [[ $cur == -* ]]; then - COMPREPLY=($(compgen -W "-a -H -p -v -Z -z -o -s -S -d -D -R -l -L -v -x " -- "${cur}")) - else - _smf_complete_fmri "${cur}" "svc:" - fi - -} && -complete -F _svcs svcs - - -# ex: ts=4 sw=4 et filetype=sh diff --git a/bash-completion/addons/svcadm b/bash-completion/addons/svcadm new file mode 100644 index 0000000..e2a7c35 --- /dev/null +++ b/bash-completion/addons/svcadm @@ -0,0 +1,175 @@ +# svcadm completion -*- shell-script -*- +# +# Copyright 2006 Yann Rouillard +# Portions copyright 2013, Nexenta Systems, Inc. + +# +# svcadm accept any complete FMRI or abreviated FMRI +# - a complete FMRI is svc:/foo/bar/bar/baz +# - abbreviated FMRI are foo/bar/bar/baz, bar/bar/baz, bar/baz or baz +# +# The goal of this function is to be able to propose all alternatives, +# but to not clutter the interface with all completions, we will only +# cut every completion alternative at the next slash. +# +# For exemple, if the user types , we will propose for svc://foo/bar/bar/baz +# the following completion: foo/, bar/ and baz +# If the user types , we will propose: bar/ and baz +# If the user types , we will propose: bar/bar/ and bar/baz +# +# By default, the function proproses only abbreviated completions except if the user already +# began to type svc:. In that case we will propose only the complete FMRI beginning with the +# pattern +# +_smf_complete_fmri () +{ + local cur="$1" prefix="$2" + local cur_prefix fmri fmri_list="" + local exact_mode pattern + + if [[ "$cur" == $prefix* ]]; then + [[ "$cur" == $prefix ]] && cur+="/" + pattern="$cur*" + exact_mode=1 + else + pattern="$prefix*/$cur*" + fi + + cur_prefix="${cur%"${cur##*/}"}" + + for fmri in $(svcs -H -o FMRI "$pattern" 2>/dev/null); do + local fmri_part_list fmri_part + if [[ -z "$exact_mode" ]]; then + fmri=${fmri#$prefix/} + + # we generate all possibles abbrevations for the FMRI + # no need to have a generic loop as we will have a finite + # number of components + local OIFS="$IFS"; IFS="/"; set -- $fmri; IFS="$OIFS" + case $# in + 1) fmri_part_list=" $1";; + 2) fmri_part_list=" $2 $1/$2";; + 3) fmri_part_list=" $3 $2/$3 $1/$2/$3";; + 4) fmri_part_list=" $4 $3/$4 $2/$3/$4 $1/$2/$3/$4";; + esac + else + fmri_part_list="$fmri" + fi + + # Here we make sure the completions begins with the pattern and + # we cut them at the first slash + for fmri_part in $fmri_part_list; do + [[ "$fmri_part" == $cur* ]] || continue + local first_part=${fmri_part#$cur_prefix} + first_part=$cur_prefix${first_part%%/*} + [[ "$first_part" != "$fmri_part" ]] && first_part+="/" + fmri_list+=" $first_part" + done + done + + COMPREPLY=( $fmri_list ) + + # here we want to detect if there only one completion proposed and that + # it ends with a slash. That means the users will still have to complete + # after, so we gain him one tab keystroke by immediately proposing the + # next completion alternatives + local i=${#COMPREPLY[*]} + if [[ $i -gt 0 ]] && [[ "${COMPREPLY[$((--i))]}" == */ ]]; then + # we have to iterate throught the list as we may have duplicate + while [[ $i -ne 0 ]]; do + [[ "${COMPREPLY[$i]}" != "${COMPREPLY[$((i - 1))]}" ]] && break + ((i--)) + done + if [[ $i -eq 0 ]]; then + _smf_complete_fmri "${COMPREPLY[0]}" "$prefix" + return 0 + fi + fi + + # Work-around bash_completion issue where bash interprets a colon + # as a separator, borrowed from maven completion code which borrowed + # it from darcs completion code :) + local colonprefixes=${cur%"${cur##*:}"} + local i=${#COMPREPLY[*]} + while [ $((--i)) -ge 0 ]; do + COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"} + done +} + +_svcadm () +{ + local cur prev words cword + _init_completion -n : || return + + local command_list="enable disable restart refresh clear mark milestone" + local command i + + for (( i=1; i < $cword; i++ )); do + if [[ ${words[i]} == @(enable|disable|restart|refresh|clear|mark|milestone) ]]; then + command=${words[i]} + fi + done + + if [[ -z "$command" ]]; then + if [[ ${cur} == -* ]] ; then + COMPREPLY=( $(compgen -W "-v" -- ${cur}) ) + else + COMPREPLY=( $(compgen -W "$command_list" -- ${cur}) ) + fi + else + if [[ ${cur} == -* ]]; then + case "$command" in + enable) + COMPREPLY=( $(compgen -W "-r -s -t" -- ${cur}) );; + disable) + COMPREPLY=( $(compgen -W "-s -t" -- ${cur}) );; + mark) + COMPREPLY=( $(compgen -W "-I -t" -- ${cur}) );; + milestone) + COMPREPLY=( $(compgen -W "-d" -- ${cur}) );; + esac + else + if [[ "$command" == "mark" ]] && [[ "$prev" != @(degraded|maintenance) ]]; then + COMPREPLY=( $(compgen -W "degraded maintenance" -- ${cur}) ) + elif [[ "$command" == "milestone" ]]; then + _smf_complete_fmri "${cur}" "svc:/milestone" + else + _smf_complete_fmri "${cur}" "svc:" + fi + fi + fi +} + +_svcs () { + local cur prev opts line + local svcs_cols="ctid desc fmri inst nsta nstate scope svc sta state stime" + COMPREPLY=() + + cur=${COMP_WORDS[COMP_CWORD]} + prev="${COMP_WORDS[COMP_CWORD-1]}" + line="${COMP_LINE}" + + case "$prev" in + -o|-s|-S) + COMPREPLY=($(compgen -W "$svcs_cols" -- "${cur##*,}")) + local existing_opts=$(expr "$cur" : '\(.*,\)') + if [[ -n "$existing_opts" ]]; then + COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" ) + fi + compopt -o nospace + return;; + esac + + if [[ $cur == -* ]]; then + COMPREPLY=($(compgen -W "-a -H -p -v -Z -z -o -s -S -d -D -R -l -L -v -x " -- "${cur}")) + else + _smf_complete_fmri "${cur}" "svc:" + fi + +} + +complete -F _svcadm svcadm +complete -F _svcs svcs + + +# ex: ts=4 sw=4 et filetype=sh diff --git a/bash-completion/addons/zfs b/bash-completion/addons/zfs new file mode 100644 index 0000000..f59d73a --- /dev/null +++ b/bash-completion/addons/zfs @@ -0,0 +1,243 @@ +# Copyright (c) 2010, Aneurin Price +# Portions copyright (c) 2013, Pashev Igor + +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: + +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. + +__zfs_get_commands() +{ + zfs 2>&1 | awk '/^\t[a-z]/ {print $1}' | uniq +} + +__zfs_get_properties() +{ + zfs get 2>&1 | awk '$2 == "YES" || $2 == "NO" {print $1}'; echo all +} + +__zfs_get_editable_properties() +{ + zfs get 2>&1 | awk '$2 == "YES" {printf("%s=\n", $1)}' +} + +__zfs_get_inheritable_properties() +{ + zfs get 2>&1 | awk '$3 == "YES" {print $1}' +} + +__zfs_list_datasets() +{ + zfs list -H -o name +} + +__zfs_list_filesystems() +{ + zfs list -H -o name -t filesystem +} + +__zfs_list_snapshots() +{ + zfs list -H -o name -t snapshot +} + +__zfs_list_volumes() +{ + zfs list -H -o name -t volume +} + +__zfs_argument_chosen() +{ + for word in $(seq $((COMP_CWORD-1)) -1 2) + do + local prev="${COMP_WORDS[$word]}" + for property in $@ + do + if [ "x$prev" = "x$property" ] + then + return 0 + fi + done + done + return 1 +} + +__zfs_complete_ordered_arguments() +{ + local list1=$1 + local list2=$2 + local cur=$3 + local extra=$4 + if __zfs_argument_chosen $list1 + then + COMPREPLY=($(compgen -W "$list2 $extra" -- "$cur")) + else + COMPREPLY=($(compgen -W "$list1 $extra" -- "$cur")) + fi +} + +__zfs_complete() +{ + local cur prev cmd cmds + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + cmd="${COMP_WORDS[1]}" + cmds=$(__zfs_get_commands) + + if [ "${prev##*/}" = "zfs" ] + then + COMPREPLY=($(compgen -W "$cmds -?" -- "$cur")) + return 0 + fi + + case "${cmd}" in + clone) + __zfs_complete_ordered_arguments "$(__zfs_list_snapshots)" "$(__zfs_list_filesystems) $(__zfs_list_volumes)" $cur + return 0 + ;; + get) + __zfs_complete_ordered_arguments "$(__zfs_get_properties)" "$(__zfs_list_datasets)" "$cur" "-H -r -p" + return 0 + ;; + inherit) + __zfs_complete_ordered_arguments "$(__zfs_get_inheritable_properties)" "$(__zfs_list_datasets)" $cur + return 0 + ;; + list) + case "$prev" in + -o) + COMPREPLY=($(compgen -W "$(__zfs_get_properties)" -- "${cur##*,}")) + local existing_opts=$(expr "$cur" : '\(.*,\)') + if [ ! "x$existing_opts" = "x" ] + then + COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" ) + fi + ;; + -t) + COMPREPLY=($(compgen -W "snapshot volume filesystem all" -- "${cur##*,}")) + local existing_opts=$(expr "$cur" : '\(.*,\)') + if [ ! "x$existing_opts" = "x" ] + then + COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" ) + fi + ;; + *) + COMPREPLY=($(compgen -W "$(__zfs_list_datasets) -H -r -o -t" -- "$cur")) + ;; + esac + return 0 + ;; + promote) + COMPREPLY=($(compgen -W "$(__zfs_list_filesystems)" -- "$cur")) + return 0 + ;; + rollback|send) + COMPREPLY=($(compgen -W "$(__zfs_list_snapshots)" -- "$cur")) + return 0 + ;; + snapshot) + COMPREPLY=($(compgen -W "$(__zfs_list_filesystems) $(__zfs_list_volumes)" -- "$cur")) + return 0 + ;; + set) + __zfs_complete_ordered_arguments "$(__zfs_get_editable_properties)" "$(__zfs_list_filesystems) $(__zfs_list_volumes)" $cur + return 0 + ;; + *) + COMPREPLY=($(compgen -W "$(__zfs_list_datasets)" -- "$cur")) + return 0 + ;; + esac + +} + +__zpool_get_commands() +{ + zpool 2>&1 | awk '/^\t[a-z]/ {print $1}' | uniq +} + +__zpool_get_properties() +{ + zpool get 2>&1 | awk '$2 == "YES" || $2 == "NO" {print $1}'; echo all +} + +__zpool_get_editable_properties() +{ + zpool get 2>&1 | awk '$2 == "YES" {printf("%s=\n", $1)}' +} + +__zpool_list_pools() +{ + zpool list -H -o name +} + +__zpool_complete() +{ + local cur prev cmd cmds + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + cmd="${COMP_WORDS[1]}" + cmds=$(__zpool_get_commands) + + if [ "${prev##*/}" = "zpool" ] + then + COMPREPLY=($(compgen -W "$cmds" -- "$cur")) + return 0 + fi + + case "${cmd}" in + get) + __zfs_complete_ordered_arguments "$(__zpool_get_properties)" "$(__zpool_list_pools)" $cur + return 0 + ;; + import) + if [ "x$prev" = "x-d" ] + then + _filedir -d + else + COMPREPLY=($(compgen -W "$(__zpool_list_pools) -d" -- "$cur")) + fi + return 0 + ;; + set) + __zfs_complete_ordered_arguments "$(__zpool_get_editable_properties)" "$(__zpool_list_pools)" $cur + return 0 + ;; + add|attach|clear|create|detach|offline|online|remove|replace) + local pools="$(__zpool_list_pools)" + if __zfs_argument_chosen $pools + then + _filedir + else + COMPREPLY=($(compgen -W "$pools" -- "$cur")) + fi + return 0 + ;; + *) + COMPREPLY=($(compgen -W "$(__zpool_list_pools)" -- "$cur")) + return 0 + ;; + esac + +} + +complete -F __zfs_complete zfs +complete -o filenames -F __zpool_complete zpool diff --git a/bash-completion/addons/zfsutils b/bash-completion/addons/zfsutils deleted file mode 100644 index f59d73a..0000000 --- a/bash-completion/addons/zfsutils +++ /dev/null @@ -1,243 +0,0 @@ -# Copyright (c) 2010, Aneurin Price -# Portions copyright (c) 2013, Pashev Igor - -# Permission is hereby granted, free of charge, to any person -# obtaining a copy of this software and associated documentation -# files (the "Software"), to deal in the Software without -# restriction, including without limitation the rights to use, -# copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the -# Software is furnished to do so, subject to the following -# conditions: - -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -# OTHER DEALINGS IN THE SOFTWARE. - -__zfs_get_commands() -{ - zfs 2>&1 | awk '/^\t[a-z]/ {print $1}' | uniq -} - -__zfs_get_properties() -{ - zfs get 2>&1 | awk '$2 == "YES" || $2 == "NO" {print $1}'; echo all -} - -__zfs_get_editable_properties() -{ - zfs get 2>&1 | awk '$2 == "YES" {printf("%s=\n", $1)}' -} - -__zfs_get_inheritable_properties() -{ - zfs get 2>&1 | awk '$3 == "YES" {print $1}' -} - -__zfs_list_datasets() -{ - zfs list -H -o name -} - -__zfs_list_filesystems() -{ - zfs list -H -o name -t filesystem -} - -__zfs_list_snapshots() -{ - zfs list -H -o name -t snapshot -} - -__zfs_list_volumes() -{ - zfs list -H -o name -t volume -} - -__zfs_argument_chosen() -{ - for word in $(seq $((COMP_CWORD-1)) -1 2) - do - local prev="${COMP_WORDS[$word]}" - for property in $@ - do - if [ "x$prev" = "x$property" ] - then - return 0 - fi - done - done - return 1 -} - -__zfs_complete_ordered_arguments() -{ - local list1=$1 - local list2=$2 - local cur=$3 - local extra=$4 - if __zfs_argument_chosen $list1 - then - COMPREPLY=($(compgen -W "$list2 $extra" -- "$cur")) - else - COMPREPLY=($(compgen -W "$list1 $extra" -- "$cur")) - fi -} - -__zfs_complete() -{ - local cur prev cmd cmds - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - cmd="${COMP_WORDS[1]}" - cmds=$(__zfs_get_commands) - - if [ "${prev##*/}" = "zfs" ] - then - COMPREPLY=($(compgen -W "$cmds -?" -- "$cur")) - return 0 - fi - - case "${cmd}" in - clone) - __zfs_complete_ordered_arguments "$(__zfs_list_snapshots)" "$(__zfs_list_filesystems) $(__zfs_list_volumes)" $cur - return 0 - ;; - get) - __zfs_complete_ordered_arguments "$(__zfs_get_properties)" "$(__zfs_list_datasets)" "$cur" "-H -r -p" - return 0 - ;; - inherit) - __zfs_complete_ordered_arguments "$(__zfs_get_inheritable_properties)" "$(__zfs_list_datasets)" $cur - return 0 - ;; - list) - case "$prev" in - -o) - COMPREPLY=($(compgen -W "$(__zfs_get_properties)" -- "${cur##*,}")) - local existing_opts=$(expr "$cur" : '\(.*,\)') - if [ ! "x$existing_opts" = "x" ] - then - COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" ) - fi - ;; - -t) - COMPREPLY=($(compgen -W "snapshot volume filesystem all" -- "${cur##*,}")) - local existing_opts=$(expr "$cur" : '\(.*,\)') - if [ ! "x$existing_opts" = "x" ] - then - COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" ) - fi - ;; - *) - COMPREPLY=($(compgen -W "$(__zfs_list_datasets) -H -r -o -t" -- "$cur")) - ;; - esac - return 0 - ;; - promote) - COMPREPLY=($(compgen -W "$(__zfs_list_filesystems)" -- "$cur")) - return 0 - ;; - rollback|send) - COMPREPLY=($(compgen -W "$(__zfs_list_snapshots)" -- "$cur")) - return 0 - ;; - snapshot) - COMPREPLY=($(compgen -W "$(__zfs_list_filesystems) $(__zfs_list_volumes)" -- "$cur")) - return 0 - ;; - set) - __zfs_complete_ordered_arguments "$(__zfs_get_editable_properties)" "$(__zfs_list_filesystems) $(__zfs_list_volumes)" $cur - return 0 - ;; - *) - COMPREPLY=($(compgen -W "$(__zfs_list_datasets)" -- "$cur")) - return 0 - ;; - esac - -} - -__zpool_get_commands() -{ - zpool 2>&1 | awk '/^\t[a-z]/ {print $1}' | uniq -} - -__zpool_get_properties() -{ - zpool get 2>&1 | awk '$2 == "YES" || $2 == "NO" {print $1}'; echo all -} - -__zpool_get_editable_properties() -{ - zpool get 2>&1 | awk '$2 == "YES" {printf("%s=\n", $1)}' -} - -__zpool_list_pools() -{ - zpool list -H -o name -} - -__zpool_complete() -{ - local cur prev cmd cmds - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - cmd="${COMP_WORDS[1]}" - cmds=$(__zpool_get_commands) - - if [ "${prev##*/}" = "zpool" ] - then - COMPREPLY=($(compgen -W "$cmds" -- "$cur")) - return 0 - fi - - case "${cmd}" in - get) - __zfs_complete_ordered_arguments "$(__zpool_get_properties)" "$(__zpool_list_pools)" $cur - return 0 - ;; - import) - if [ "x$prev" = "x-d" ] - then - _filedir -d - else - COMPREPLY=($(compgen -W "$(__zpool_list_pools) -d" -- "$cur")) - fi - return 0 - ;; - set) - __zfs_complete_ordered_arguments "$(__zpool_get_editable_properties)" "$(__zpool_list_pools)" $cur - return 0 - ;; - add|attach|clear|create|detach|offline|online|remove|replace) - local pools="$(__zpool_list_pools)" - if __zfs_argument_chosen $pools - then - _filedir - else - COMPREPLY=($(compgen -W "$pools" -- "$cur")) - fi - return 0 - ;; - *) - COMPREPLY=($(compgen -W "$(__zpool_list_pools)" -- "$cur")) - return 0 - ;; - esac - -} - -complete -F __zfs_complete zfs -complete -o filenames -F __zpool_complete zpool diff --git a/bash-completion/bash-completion.p5m b/bash-completion/bash-completion.p5m index ccf9caa..4d2334c 100644 --- a/bash-completion/bash-completion.p5m +++ b/bash-completion/bash-completion.p5m @@ -2,7 +2,7 @@ set name=pkg.fmri value=pkg:/shell/bash-completion@$(ips-version) set name=pkg.summary value="$(summary)" set name=info.upstream-url value="$(home)" set name=info.source-url value="$(download)" -license $(license-file) license="$(license)" +license $(license-file) license="$(license)" dir path=usr/share/bash-completion dir path=usr/share/bash-completion/completions @@ -12,8 +12,12 @@ file path=etc/profile.d/bash_completion.sh file addons/beadm path=usr/share/bash-completion/completions/beadm file addons/bootadm path=usr/share/bash-completion/completions/bootadm -file addons/smf path=usr/share/bash-completion/completions/smf -file addons/zfsutils path=usr/share/bash-completion/completions/zfsutils + +file addons/zfs path=usr/share/bash-completion/completions/zfs +link target=zfs path=usr/share/bash-completion/completions/zpool + +file addons/svcadm path=usr/share/bash-completion/completions/svcadm +link target=svcadm path=usr/share/bash-completion/completions/svcs file path=usr/share/bash-completion/bash_completion file path=usr/share/bash-completion/completions/kldunload -- cgit v1.2.3