Skip to content

Commit 8260af5

Browse files
committed
image: enable basic tab completion for bash
1 parent f6248bd commit 8260af5

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

image/templates/files/bash_completion

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

image/templates/files/bashrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@ pathdirs=(
4545
'/opt/ooce/bin'
4646
'/opt/oxide/opte/bin'
4747
'/opt/oxide/mg-ddm'
48+
'/opt/oxide/oxlog'
4849
'/usr/sbin'
4950
'/usr/bin'
5051
'/bin'
5152
'/sbin'
5253
)
5354
export PATH=$(IFS=':'; printf '%s' "${pathdirs[*]}")
5455

56+
. /usr/share/bash/oxide_completion
57+
5558
#
5659
# Bracketed paste in bash is a deeply questionable facility, and on a serial
5760
# console where one may reset the system at any time it leaves the terminal in

image/templates/gimlet/ramdisk-02-trim.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@
106106
"file": "/etc/motd",
107107
"src": "motd",
108108
"owner": "root", "group": "sys", "mode": "0644" },
109+
{ "t": "ensure_file",
110+
"file": "/usr/share/bash/oxide_completion",
111+
"src": "bash_completion",
112+
"owner": "root", "group": "root", "mode": "0644" },
109113

110114
{ "t": "ensure_file",
111115
"file": "/etc/system.d/zfs:dbuf",

0 commit comments

Comments
 (0)