Skip to content

Commit

Permalink
image: enable basic tab completion for bash
Browse files Browse the repository at this point in the history
  • Loading branch information
citrus-it committed Apr 19, 2024
1 parent f6248bd commit f6e823e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
85 changes: 85 additions & 0 deletions image/templates/files/bash_completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# This file is derived from completion fragments at
# https://github.com/OpenIndiana/openindiana-completions
#
# Portions Copyright 2006 Yann Rouillard <[email protected]>
# Portions Copyright (c) 2013, Jonathan Perkin <[email protected]>
# Portions copyright 2013, Nexenta Systems, Inc.
# Portions Copyright (c) 2018, Michal Nowak <[email protected]>
# Portions Copyright 2024 Oxide Computer Company

shopt -s extglob progcomp

_zlogin()
{
local cur prev line
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
line="${COMP_LINE}"

# zlogin [-dCEQ] [-e c] [-l username] zonename
# zlogin [-nEQS] [-e c] [-l username] zonename utility [argument]...
local opts="-E -Q -e -l"
local opts_interactive="-d -C"
local opts_util="-n -S"

if [[ "${cur}" == -* ]]
then
case "${line}" in
*\ -n\ *|*\ -S\ *)
COMPREPLY=( $(compgen -W "${opts} ${opts_util}" -- "${cur}") )
;;
*\ -d\ *|*\ -C\ *)
COMPREPLY=( $(compgen -W "${opts} ${opts_interactive}" -- "${cur}") )
;;
*)
COMPREPLY=( $(compgen -W "${opts} ${opts_util} ${opts_interactive}" -- "${cur}") )
;;
esac
else
# Provide running zone names
local zones=$(zoneadm list -n)
COMPREPLY=( $(compgen -W "${zones}" -- ${cur}) )
fi
}

_dash_z_zone()
{
local cur prev
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

if [[ ${prev} =~ "-z" ]]; then
local zones="$(zoneadm list -n $*)"
COMPREPLY=( $(compgen -W "${zones}" -- ${cur}) )
fi
}

_dash_z_zone_running() { _dash_z_zone; }
_dash_z_zone_configured() { _dash_z_zone -c; }

complete -F _zlogin zlogin

# Many illumos utilities are zone-aware through the -z option
#
complete -F _dash_z_zone_running allocate
complete -F _dash_z_zone_running deallocate
complete -F _dash_z_zone_running ipfs
complete -F _dash_z_zone_running ipfstat
complete -F _dash_z_zone_running ipmon
complete -F _dash_z_zone_running ipnat
complete -F _dash_z_zone_running ippool
complete -F _dash_z_zone_running pgrep
complete -F _dash_z_zone_running pkill
complete -F _dash_z_zone_running ps
complete -F _dash_z_zone_running psrset
complete -F _dash_z_zone_running ptree
complete -F _dash_z_zone_running svccfg
complete -F _dash_z_zone_running svcprop
complete -F _dash_z_zone_running wall

complete -F _dash_z_zone_configured auditreduce
complete -F _dash_z_zone_configured zoneadm
complete -F _dash_z_zone_configured zonecfg

# ex: filetype=sh
# vim: tabstop=2 shiftwidth=2 expandtab
3 changes: 3 additions & 0 deletions image/templates/files/bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ pathdirs=(
'/opt/ooce/bin'
'/opt/oxide/opte/bin'
'/opt/oxide/mg-ddm'
'/opt/oxide/oxlog'
'/usr/sbin'
'/usr/bin'
'/bin'
'/sbin'
)
export PATH=$(IFS=':'; printf '%s' "${pathdirs[*]}")

. /usr/share/bash/oxide_completion

#
# Bracketed paste in bash is a deeply questionable facility, and on a serial
# console where one may reset the system at any time it leaves the terminal in
Expand Down
4 changes: 4 additions & 0 deletions image/templates/gimlet/ramdisk-02-trim.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@
"file": "/etc/motd",
"src": "motd",
"owner": "root", "group": "sys", "mode": "0644" },
{ "t": "ensure_file",
"file": "/usr/share/bash/oxide_completion",
"src": "bash_completion",
"owner": "root", "group": "root", "mode": "0644" },

{ "t": "ensure_file",
"file": "/etc/system.d/zfs:dbuf",
Expand Down

0 comments on commit f6e823e

Please sign in to comment.