Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image: enable basic tab completion for bash #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions image/templates/files/bash_completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# 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 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 svcadm
complete -F _dash_z_zone_running svcs
complete -F _dash_z_zone_running svccfg
complete -F _dash_z_zone_running svcprop

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