|
| 1 | +# This file is derived from completion fragments at |
| 2 | +# https://github.com/OpenIndiana/openindiana-completions |
| 3 | +# |
| 4 | +# Portions Copyright 2006 Yann Rouillard <yann@opencsw.org> |
| 5 | +# Portions Copyright (c) 2013, Jonathan Perkin <jperkin@joyent.com> |
| 6 | +# Portions copyright 2013, Nexenta Systems, Inc. |
| 7 | +# Portions Copyright (c) 2018, Michal Nowak <mnowak@startmail.com> |
| 8 | +# Portions Copyright 2024 Oxide Computer Company |
| 9 | + |
| 10 | +shopt -s extglob progcomp |
| 11 | + |
| 12 | +_zlogin() |
| 13 | +{ |
| 14 | + local cur prev line |
| 15 | + cur="${COMP_WORDS[COMP_CWORD]}" |
| 16 | + prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 17 | + line="${COMP_LINE}" |
| 18 | + |
| 19 | + # zlogin [-dCEQ] [-e c] [-l username] zonename |
| 20 | + # zlogin [-nEQS] [-e c] [-l username] zonename utility [argument]... |
| 21 | + local opts="-E -Q -e -l" |
| 22 | + local opts_interactive="-d -C" |
| 23 | + local opts_util="-n -S" |
| 24 | + |
| 25 | + if [[ "${cur}" == -* ]] |
| 26 | + then |
| 27 | + case "${line}" in |
| 28 | + *\ -n\ *|*\ -S\ *) |
| 29 | + COMPREPLY=( $(compgen -W "${opts} ${opts_util}" -- "${cur}") ) |
| 30 | + ;; |
| 31 | + *\ -d\ *|*\ -C\ *) |
| 32 | + COMPREPLY=( $(compgen -W "${opts} ${opts_interactive}" -- "${cur}") ) |
| 33 | + ;; |
| 34 | + *) |
| 35 | + COMPREPLY=( $(compgen -W "${opts} ${opts_util} ${opts_interactive}" -- "${cur}") ) |
| 36 | + ;; |
| 37 | + esac |
| 38 | + else |
| 39 | + # Provide running zone names |
| 40 | + local zones=$(zoneadm list -n) |
| 41 | + COMPREPLY=( $(compgen -W "${zones}" -- ${cur}) ) |
| 42 | + fi |
| 43 | +} |
| 44 | + |
| 45 | +_dash_z_zone() |
| 46 | +{ |
| 47 | + local cur prev |
| 48 | + cur="${COMP_WORDS[COMP_CWORD]}" |
| 49 | + prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 50 | + |
| 51 | + if [[ ${prev} =~ "-z" ]]; then |
| 52 | + local zones="$(zoneadm list -n $*)" |
| 53 | + COMPREPLY=( $(compgen -W "${zones}" -- ${cur}) ) |
| 54 | + fi |
| 55 | +} |
| 56 | + |
| 57 | +_dash_z_zone_running() { _dash_z_zone; } |
| 58 | +_dash_z_zone_configured() { _dash_z_zone -c; } |
| 59 | + |
| 60 | +complete -F _zlogin zlogin |
| 61 | + |
| 62 | +# Many illumos utilities are zone-aware through the -z option |
| 63 | +# |
| 64 | +complete -F _dash_z_zone_running pgrep |
| 65 | +complete -F _dash_z_zone_running pkill |
| 66 | +complete -F _dash_z_zone_running ps |
| 67 | +complete -F _dash_z_zone_running psrset |
| 68 | +complete -F _dash_z_zone_running ptree |
| 69 | +complete -F _dash_z_zone_running svcadm |
| 70 | +complete -F _dash_z_zone_running svcs |
| 71 | +complete -F _dash_z_zone_running svccfg |
| 72 | +complete -F _dash_z_zone_running svcprop |
| 73 | + |
| 74 | +complete -F _dash_z_zone_configured zoneadm |
| 75 | +complete -F _dash_z_zone_configured zonecfg |
| 76 | + |
| 77 | +# ex: filetype=sh |
| 78 | +# vim: tabstop=2 shiftwidth=2 expandtab |
0 commit comments