summaryrefslogtreecommitdiff
path: root/usr/src/cmd/nsadmin/bash/bash_completion.d
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/cmd/nsadmin/bash/bash_completion.d')
-rw-r--r--usr/src/cmd/nsadmin/bash/bash_completion.d/dladm34
-rw-r--r--usr/src/cmd/nsadmin/bash/bash_completion.d/machines19
-rw-r--r--usr/src/cmd/nsadmin/bash/bash_completion.d/vms62
-rw-r--r--usr/src/cmd/nsadmin/bash/bash_completion.d/zone_alias42
-rw-r--r--usr/src/cmd/nsadmin/bash/bash_completion.d/zones50
5 files changed, 207 insertions, 0 deletions
diff --git a/usr/src/cmd/nsadmin/bash/bash_completion.d/dladm b/usr/src/cmd/nsadmin/bash/bash_completion.d/dladm
new file mode 100644
index 0000000000..179227b2a2
--- /dev/null
+++ b/usr/src/cmd/nsadmin/bash/bash_completion.d/dladm
@@ -0,0 +1,34 @@
+_dladm()
+{
+ local cur prev opts base
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+ if [[ ${prev} == 'dladm' ]]; then
+ local cmds="rename-link show-link create-aggr delete-aggr add-aggr \
+ remove-aggr modify-aggr show-aggr scan-wifi connect-wifi \
+ disconnect-wifi show-wifi set-linkprop reset-linkprop \
+ show-linkprop show-ether create-secobj delete-secobj show-secobj \
+ create-vlan delete-vlan show-vlan create-iptun delete-iptun \
+ modify-iptun show-iptun delete-phys show-phys create-vnic \
+ delete-vnic show-vnic create-part delete-part show-part show-ib \
+ create-etherstub delete-etherstub show-etherstub create-bridge \
+ modify-bridge delete-bridge add-bridge remove-bridge show-bridge \
+ show-bridge show-usage"
+
+ COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) )
+ # The -z takes a zone option, ignore everything else
+ elif [[ ${prev} =~ -.*z$ ]]; then
+ local zones=$(zoneadm list -c | grep -v '^global$')
+ COMPREPLY=( $(compgen -W "${zones}" -- ${cur}) )
+ elif [[ ${prev} =~ 'delete-vnic' ]]; then
+ local vnics=$(dladm show-vnic -p -o link)
+ COMPREPLY=( $(compgen -W "${vnics}" -- ${cur}) )
+ elif [[ ${prev} =~ 'delete-etherstub' ]]; then
+ local stubs=$(dladm show-etherstub -p)
+ COMPREPLY=( $(compgen -W "${stubs}" -- ${cur}) )
+ fi
+}
+
+complete -F _dladm dladm
diff --git a/usr/src/cmd/nsadmin/bash/bash_completion.d/machines b/usr/src/cmd/nsadmin/bash/bash_completion.d/machines
new file mode 100644
index 0000000000..05de1b75a4
--- /dev/null
+++ b/usr/src/cmd/nsadmin/bash/bash_completion.d/machines
@@ -0,0 +1,19 @@
+_machine()
+{
+ local cur prev opts base
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+ if [[ ${prev} == 'machine-json' ]]; then
+ machines=$(zoneadm list -cp | grep -v ':global:' | cut -d':' -f2,5 | tr ':' '\n' | sort | uniq)
+ COMPREPLY=( $(compgen -W "${machines}" -- ${cur}) )
+ else
+ # Just expand files by default
+ COMPREPLY=( $(compgen -f -- ${cur}) )
+ fi
+
+ return 0
+}
+
+complete -F _machine machine-json
diff --git a/usr/src/cmd/nsadmin/bash/bash_completion.d/vms b/usr/src/cmd/nsadmin/bash/bash_completion.d/vms
new file mode 100644
index 0000000000..71bcac5994
--- /dev/null
+++ b/usr/src/cmd/nsadmin/bash/bash_completion.d/vms
@@ -0,0 +1,62 @@
+_vmadm()
+{
+ local cur prev opts base
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+ up_patterns=$(printf " running *\$\n halting *\$\n")
+
+ if [[ ${prev} == 'vmadm' ]]; then
+ COMPREPLY=( $(compgen -W "boot destroy dump kill halt list reboot reset info nmi" -- ${cur}) )
+ else
+ case ${prev} in
+ boot)
+ local not_running=$(vmadm list -v | grep -v "^UUID" | \
+ /usr/xpg4/bin/grep -v -e "${up_patterns}" | cut -d' ' -f1)
+ COMPREPLY=( $(compgen -W "${not_running}" -- ${cur}) )
+ ;;
+ info|kill)
+ local running=$(vmadm list -v | grep -v "^UUID" | \
+ /usr/xpg4/bin/grep -e "${up_patterns}" | cut -d ' ' -f1)
+ COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
+ ;;
+ halt|reboot|reset|nmi|screenshot)
+ local running=$(vmadm list -v | grep -v "^UUID" | \
+ grep " running *$" | cut -d ' ' -f1)
+ COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
+ ;;
+ dump|destroy)
+ local all=$(vmadm list)
+ COMPREPLY=( $(compgen -W "${all}" -- ${cur}) )
+ ;;
+ *)
+ # Just expand files by default
+ COMPREPLY=( $(compgen -f -- ${cur}) )
+ ;;
+ esac
+ fi
+
+ return 0
+}
+
+_vmcfg()
+{
+ local cur prev opts base
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+ if [[ ${prev} == 'vmcfg' ]]; then
+ vms=$(vmadm list)
+ COMPREPLY=( $(compgen -W "${vms}" -- ${cur}) )
+ else
+ # Just expand files by default
+ COMPREPLY=( $(compgen -f -- ${cur}) )
+ fi
+
+ return 0
+}
+
+complete -F _vmadm vmadm
+complete -F _vmcfg vmcfg
diff --git a/usr/src/cmd/nsadmin/bash/bash_completion.d/zone_alias b/usr/src/cmd/nsadmin/bash/bash_completion.d/zone_alias
new file mode 100644
index 0000000000..5ae8e1d7c7
--- /dev/null
+++ b/usr/src/cmd/nsadmin/bash/bash_completion.d/zone_alias
@@ -0,0 +1,42 @@
+_zone_alias()
+{
+ local RES alias completed_alias results_arr uuid
+ # Attempt alias -> uuid mapping
+ alias="${COMP_WORDS[COMP_CWORD]}"
+ RES=$(vmadm list -H -o alias,uuid | awk -v alias="$alias" '
+ BEGIN { count = 0; uuid = ""; }
+ $1 == alias { count = 1; aliases[1] = $1; uuid = $2; exit;}
+ $1 ~ "^"alias { count += 1; aliases[count] = $1; uuid = $2; }
+ END { if (count == 1) {
+ print "smartos_alias_completed " aliases[1] " " uuid;
+ } else {
+ for (i=1; i <= count; i++) {
+ print aliases[i]
+ }
+ }
+ }
+ ')
+ results_arr=( $RES )
+ # we use 'smartos_alias_completed' as a flag to determine that
+ # a single alias was matched.
+ if [[ "${results_arr[0]}" == "smartos_alias_completed" ]]; then
+ completed_alias="${results_arr[1]}"
+ uuid="${results_arr[2]}"
+ if [[ -n "$SMARTOS_MULTILINE_ALIAS_COMPLETION" ]]; then
+ tput sc
+ tput bold
+ echo "[completed alias: ${completed_alias}]"
+ tput rc
+ tput sgr0
+ COMPREPLY=$uuid
+ elif [[ "$completed_alias" == "$alias" ]]; then
+ COMPREPLY=$uuid
+ else
+ COMPREPLY=$completed_alias
+ compopt -o nospace
+ fi
+ else
+ COMPREPLY=( $(compgen -W "$RES" -- ${cur}) )
+ fi
+ return 0
+}
diff --git a/usr/src/cmd/nsadmin/bash/bash_completion.d/zones b/usr/src/cmd/nsadmin/bash/bash_completion.d/zones
new file mode 100644
index 0000000000..e4bc5b4155
--- /dev/null
+++ b/usr/src/cmd/nsadmin/bash/bash_completion.d/zones
@@ -0,0 +1,50 @@
+_zlogin()
+{
+ local cur prev opts base
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+ # The -e and -l take non-zone arguments, otherwise complete zone
+ if [[ ${prev} != '-e' ]] && [[ ${prev} != '-l' ]]; then
+ local running=$(zoneadm list | grep -v '^global$')
+ COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
+ fi
+ if [[ -n "$COMPREPLY" ]]; then
+ return 0
+ fi
+
+ _zone_alias
+ return 0
+}
+
+_dash_z_zone()
+{
+ local cur prev opts base
+ COMPREPLY=()
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+ # The -z takes a zone option, ignore everything else
+ if [[ ${prev} =~ -.*z$ ]]; then
+ local zones=$(zoneadm list -c | grep -v '^global$')
+ COMPREPLY=( $(compgen -W "${zones}" -- ${cur}) )
+ if [[ -n "$COMPREPLY" ]]; then
+ return 0
+ fi
+ _zone_alias
+ fi
+ return 0
+}
+
+complete -F _zlogin zlogin
+complete -F _dash_z_zone zoneadm
+complete -F _dash_z_zone zonecfg
+complete -F _dash_z_zone svcs
+complete -F _dash_z_zone svcadm
+complete -F _dash_z_zone svcprop
+complete -F _dash_z_zone pgrep
+complete -F _dash_z_zone pkill
+complete -F _dash_z_zone ps
+complete -F _dash_z_zone ptree
+complete -F _dash_z_zone wall