summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bash-completion/addons/beadm129
-rw-r--r--bash-completion/addons/bootadm54
-rw-r--r--bash-completion/addons/smf174
-rw-r--r--bash-completion/addons/zfsutils243
-rw-r--r--bash-completion/bash-completion.p5m5
5 files changed, 605 insertions, 0 deletions
diff --git a/bash-completion/addons/beadm b/bash-completion/addons/beadm
new file mode 100644
index 0000000..cf0a73a
--- /dev/null
+++ b/bash-completion/addons/beadm
@@ -0,0 +1,129 @@
+# *** Public Domain ***
+#
+# Uncomment if do not have zfs bash completion:
+#__zfs_get_editable_properties()
+#{
+# zfs get 2>&1 | awk '$2 == "YES" {printf("%s=\n", $1)}'
+#}
+#
+#__zpool_list_pools()
+#{
+# zpool list -H -o name
+#}
+
+__beadm_be_list () {
+ beadm list -H 2>/dev/null | nawk -F';' '{print $1}'
+}
+
+__beadm_be_at_list () {
+ beadm list -H 2>/dev/null | nawk -F';' '{print $1"@"}'
+}
+
+# List of mounted BE and mount points (for unmount command)
+__beadm_unmount_list () {
+ beadm list -H 2>/dev/null | nawk -F';' '$4 != "/" && $4 != "" {print $1" "$4}'
+}
+
+__beadm_nonactive_list () {
+ beadm list -H 2>/dev/null | nawk -F';' '$3 !~ "N" {print $1}'
+}
+
+__beadm_nonactive_reboot_list () {
+ beadm list -H 2>/dev/null | nawk -F';' '$3 !~ "R" {print $1}'
+}
+
+__beadm_snapshot_list () {
+ beadm list -s -H 2>/dev/null | nawk -F';' '{print $2}'
+}
+
+_beadm () {
+ local cur prev opts line
+ COMPREPLY=()
+
+ # Allow @ (at-sign) for snapshots:
+ shopt -u hostcomplete
+
+ cur=${COMP_WORDS[COMP_CWORD]}
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+ line="${COMP_LINE}"
+ cmd="${COMP_WORDS[1]}"
+
+ if [[ ${COMP_CWORD} -eq 1 ]]; then
+ COMPREPLY=( $(compgen -W "create destroy list mount \
+ unmount rename activate rollback" -- $cur) )
+ return
+ fi
+
+ case "$cmd" in
+ create)
+ case "$prev" in
+ -e)
+ COMPREPLY=( $(compgen -W "$(__beadm_nonactive_list) $(__beadm_snapshot_list)" -- $cur) )
+ ;;
+ -p)
+ COMPREPLY=( $(compgen -W "$(__zpool_list_pools)" -- $cur) )
+ ;;
+ -o)
+ COMPREPLY=( $(compgen -W "$(__zfs_get_editable_properties)" -- $cur) )
+ ;;
+ *)
+ COMPREPLY=( $(compgen -W "-a -d -e -o -p -v $(__beadm_be_at_list)" -- $cur) )
+ if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} != -* ]]; then
+ compopt -o nospace
+ fi
+ ;;
+ esac
+ ;;
+ destroy)
+ case "$line" in
+ *"-s "*)
+ COMPREPLY=( $(compgen -W "$(__beadm_nonactive_list) -f -F -v" -- $cur) )
+ ;;
+ *)
+ COMPREPLY=( $(compgen -W "$(__beadm_snapshot_list) $(__beadm_nonactive_list) -f -s -F -v" -- $cur) )
+ ;;
+ esac
+ ;;
+ list)
+ case "$line" in
+ *"-a "*)
+ COMPREPLY=( $(compgen -W "$(__beadm_be_list) -H -v" -- $cur) )
+ ;;
+ *"-d "*)
+ COMPREPLY=( $(compgen -W "$(__beadm_be_list) -s -H -v" -- $cur) )
+ ;;
+ *"-s "*)
+ COMPREPLY=( $(compgen -W "$(__beadm_be_list) -d -H -v" -- $cur) )
+ ;;
+ *)
+ COMPREPLY=( $(compgen -W "$(__beadm_be_list) -a -d -s -H -v" -- $cur) )
+ ;;
+ esac
+ ;;
+ mount)
+ case "$prev" in
+ mount)
+ COMPREPLY=( $(compgen -W "$(__beadm_be_list) -v" -- $cur) )
+ ;;
+ -v)
+ COMPREPLY=( $(compgen -W "$(__beadm_be_list)" -- $cur) )
+ ;;
+ *)
+ _cd
+ ;;
+ esac
+ ;;
+ unmount)
+ COMPREPLY=( $(compgen -W "$(__beadm_unmount_list) -v -f" -- $cur) )
+ ;;
+ rollback)
+ COMPREPLY=( $(compgen -W "$(__beadm_snapshot_list) -v" -- $cur) )
+ ;;
+ activate)
+ COMPREPLY=( $(compgen -W "$(__beadm_nonactive_reboot_list) -v" -- $cur) )
+ ;;
+ esac
+
+}
+
+complete -F _beadm beadm
diff --git a/bash-completion/addons/bootadm b/bash-completion/addons/bootadm
new file mode 100644
index 0000000..89963af
--- /dev/null
+++ b/bash-completion/addons/bootadm
@@ -0,0 +1,54 @@
+_bootadm () {
+ local cur prev opts line
+ COMPREPLY=()
+
+ cur=${COMP_WORDS[COMP_CWORD]}
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+ line="${COMP_LINE}"
+
+ if [[ ${COMP_CWORD} -eq 1 ]]; then
+ COMPREPLY=( $(compgen -W "update-archive list-archive set-menu list-menu" -- $cur) )
+ return
+ fi
+
+ case "$prev" in
+ -R)
+ _cd
+ return;;
+ -p)
+ COMPREPLY=( $(compgen -W "i86pc sun4v sun4u" -- $cur) )
+ return;;
+ list-menu)
+ COMPREPLY=( $(compgen -W "-R" -- $cur) )
+ return;;
+ esac
+
+ case "$line" in
+ *update-archive*-R*)
+ COMPREPLY=( $(compgen -W "-v -n -f -F -p" -- $cur) )
+ ;;
+ *update-archive*)
+ COMPREPLY=( $(compgen -W "-v -n -f -F -R" -- $cur) )
+ ;;
+ *list-archive*-R*)
+ COMPREPLY=( $(compgen -W "-p" -- $cur) )
+ ;;
+ *list-archive*)
+ COMPREPLY=( $(compgen -W "-R" -- $cur) )
+ ;;
+ *set-menu*-R*)
+ COMPREPLY=( $(compgen -W "default= timeout=" -- $cur) )
+ compopt -o nospace
+ ;;
+ *set-menu*)
+ COMPREPLY=( $(compgen -W "-R default= timeout=" -- $cur) )
+ if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} != -R ]]; then
+ compopt -o nospace
+ fi
+ ;;
+ esac
+
+}
+
+complete -F _bootadm bootadm
+
diff --git a/bash-completion/addons/smf b/bash-completion/addons/smf
new file mode 100644
index 0000000..57ce673
--- /dev/null
+++ b/bash-completion/addons/smf
@@ -0,0 +1,174 @@
+# svcadm completion -*- shell-script -*-
+#
+# Copyright 2006 Yann Rouillard <yann@opencsw.org>
+
+#
+# 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 <nothing><tab>, we will propose for svc://foo/bar/bar/baz
+# the following completion: foo/, bar/ and baz
+# If the user types <b><tab>, we will propose: bar/ and baz
+# If the user types <bar/><tab>, 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/zfsutils b/bash-completion/addons/zfsutils
new file mode 100644
index 0000000..f59d73a
--- /dev/null
+++ b/bash-completion/addons/zfsutils
@@ -0,0 +1,243 @@
+# Copyright (c) 2010, Aneurin Price <aneurin.price@gmail.com>
+# Portions copyright (c) 2013, Pashev Igor <pashev.igor@gmail.com>
+
+# 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 f0b84a6..ccf9caa 100644
--- a/bash-completion/bash-completion.p5m
+++ b/bash-completion/bash-completion.p5m
@@ -10,6 +10,11 @@ dir path=usr/share/bash-completion/helpers
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 path=usr/share/bash-completion/bash_completion
file path=usr/share/bash-completion/completions/kldunload
file path=usr/share/bash-completion/completions/smartctl