From f6e823e993f7687f47d02f3fcac82d6035969d0c Mon Sep 17 00:00:00 2001 From: Andy Fiddaman Date: Fri, 19 Apr 2024 10:04:30 +0000 Subject: [PATCH] image: enable basic tab completion for bash --- image/templates/files/bash_completion | 85 +++++++++++++++++++++ image/templates/files/bashrc | 3 + image/templates/gimlet/ramdisk-02-trim.json | 4 + 3 files changed, 92 insertions(+) create mode 100644 image/templates/files/bash_completion diff --git a/image/templates/files/bash_completion b/image/templates/files/bash_completion new file mode 100644 index 0000000..0c00d80 --- /dev/null +++ b/image/templates/files/bash_completion @@ -0,0 +1,85 @@ +# This file is derived from completion fragments at +# https://github.com/OpenIndiana/openindiana-completions +# +# Portions Copyright 2006 Yann Rouillard +# Portions Copyright (c) 2013, Jonathan Perkin +# Portions copyright 2013, Nexenta Systems, Inc. +# Portions Copyright (c) 2018, Michal Nowak +# 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 diff --git a/image/templates/files/bashrc b/image/templates/files/bashrc index 169f632..d9a4b00 100644 --- a/image/templates/files/bashrc +++ b/image/templates/files/bashrc @@ -45,6 +45,7 @@ pathdirs=( '/opt/ooce/bin' '/opt/oxide/opte/bin' '/opt/oxide/mg-ddm' + '/opt/oxide/oxlog' '/usr/sbin' '/usr/bin' '/bin' @@ -52,6 +53,8 @@ pathdirs=( ) 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 diff --git a/image/templates/gimlet/ramdisk-02-trim.json b/image/templates/gimlet/ramdisk-02-trim.json index 434d330..f4d550c 100644 --- a/image/templates/gimlet/ramdisk-02-trim.json +++ b/image/templates/gimlet/ramdisk-02-trim.json @@ -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",