Skip to content

Commit c545e1a

Browse files
committed
Add bash-completion support
1 parent 2386cf0 commit c545e1a

File tree

4 files changed

+159
-1
lines changed

4 files changed

+159
-1
lines changed

Makefile.am

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CLEANFILES =
66

77
bootlibdir = $(prefix)/lib/systemd/boot/efi-sbp
88
installerdir = $(prefix)/bin
9+
bashcompletiondir = @bashcompletiondir@
910

1011
# ------------------------------------------------------------------------------
1112

@@ -177,3 +178,12 @@ man/%.1: man/%.xml
177178
http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
178179

179180
CLEANFILES += $(man_MANS)
181+
182+
# ------------------------------------------------------------------------------
183+
184+
bashcompletion_data = \
185+
completion/bash/sbpctl
186+
187+
if ENABLE_BASH_COMPLETION
188+
bashcompletion_DATA = $(bashcompletion_data)
189+
endif

completion/bash/sbpctl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# sbpctl(1) completion -*- shell-script -*-
2+
3+
_sbpctl() {
4+
local cur words cword
5+
_init_completion || return
6+
[ "$cword" -eq 1 ] && {
7+
COMPREPLY=( $(compgen -W 'install standalone generate' -- "$cur") )
8+
} || {
9+
case "${words[1]}" in
10+
"generate")
11+
COMPREPLY=()
12+
;;
13+
"install")
14+
_filedir -d
15+
;;
16+
"standalone")
17+
_filedir
18+
;;
19+
esac
20+
}
21+
}
22+
23+
complete -F _sbpctl sbpctl

configure.ac

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ AC_CHECK_HEADERS(efi/${EFI_ARCH}/efibind.h, [AC_DEFINE(HAVE_GNUEFI, 1, [Define i
3131
[AC_MSG_ERROR([*** gnuefi is required])])
3232
efiroot=$(echo $(cd /usr/lib/$(${CC} -print-multi-os-directory); pwd))
3333
EFI_LIB_DIR="$efiroot"
34-
AC_ARG_WITH(efi-libdir, AS_HELP_STRING([--with-efi-libdir=PATH], [Path to EFI lib directory]),
34+
AC_ARG_WITH(efi-libdir, AS_HELP_STRING([--with-efi-libdir=PATH], [Path to EFI lib directory]),
3535
[EFI_LIB_DIR="$withval"], [EFI_LIB_DIR="$efiroot"])
3636
AC_SUBST([EFI_LIB_DIR])
3737
have_efi_lds=no
@@ -58,14 +58,24 @@ AC_ARG_ENABLE([secure-boot-password], AS_HELP_STRING([--disable-secure-boot-pass
5858
AC_DEFINE_UNQUOTED([SECURE_BOOT_PASSWORD], `test ! "x$secure_boot_password" != "xfalse"; echo $?`,
5959
[Define if Secure Boot password is allowed])
6060

61+
AC_ARG_WITH([bashcompletiondir], AS_HELP_STRING([--with-bashcompletiondir=DIR],
62+
[Bash completions directory]), [], [AS_IF([$($PKG_CONFIG --exists bash-completion)],
63+
[with_bashcompletiondir=$($PKG_CONFIG --variable=completionsdir bash-completion)],
64+
[with_bashcompletiondir=${datadir}/bash-completion/completions])])
65+
AM_CONDITIONAL(ENABLE_BASH_COMPLETION, [test "$with_bashcompletiondir" != "no"])
66+
AX_NORMALIZE_PATH([with_bashcompletiondir])
67+
AC_SUBST([bashcompletiondir], [$with_bashcompletiondir])
68+
6169
AC_OUTPUT
6270
AC_MSG_RESULT([
6371
$PACKAGE_NAME $VERSION
6472
prefix: ${prefix}
73+
datarootdir: ${datarootdir}
6574
arch: $EFI_ARCH
6675
EFI machine type: $MACHINE_TYPE_NAME
6776
EFI libdir: ${EFI_LIB_DIR}
6877
EFI ldsdir: ${EFI_LDS_DIR}
6978
EFI includedir: ${EFI_INC_DIR}
7079
Allow Secure Boot password: ${secure_boot_password}
80+
Bash completions dir: ${with_bashcompletiondir}
7181
])

m4/ax_normalize_path.m4

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# ===========================================================================
2+
# http://www.gnu.org/software/autoconf-archive/ax_normalize_path.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_NORMALIZE_PATH(VARNAME, [REFERENCE_STRING])
8+
#
9+
# DESCRIPTION
10+
#
11+
# Perform some cleanups on the value of $VARNAME (interpreted as a path):
12+
#
13+
# - empty paths are changed to '.'
14+
# - trailing slashes are removed
15+
# - repeated slashes are squeezed except a leading doubled slash '//'
16+
# (which might indicate a networked disk on some OS).
17+
#
18+
# REFERENCE_STRING is used to turn '/' into '\' and vice-versa: if
19+
# REFERENCE_STRING contains some backslashes, all slashes and backslashes
20+
# are turned into backslashes, otherwise they are all turned into slashes.
21+
#
22+
# This makes processing of DOS filenames quite easier, because you can
23+
# turn a filename to the Unix notation, make your processing, and turn it
24+
# back to original notation.
25+
#
26+
# filename='A:\FOO\\BAR\'
27+
# old_filename="$filename"
28+
# # Switch to the unix notation
29+
# AX_NORMALIZE_PATH([filename], ["/"])
30+
# # now we have $filename = 'A:/FOO/BAR' and we can process it as if
31+
# # it was a Unix path. For instance let's say that you want
32+
# # to append '/subpath':
33+
# filename="$filename/subpath"
34+
# # finally switch back to the original notation
35+
# AX_NORMALIZE_PATH([filename], ["$old_filename"])
36+
# # now $filename equals to 'A:\FOO\BAR\subpath'
37+
#
38+
# One good reason to make all path processing with the unix convention is
39+
# that backslashes have a special meaning in many cases. For instance
40+
#
41+
# expr 'A:\FOO' : 'A:\Foo'
42+
#
43+
# will return 0 because the second argument is a regex in which
44+
# backslashes have to be backslashed. In other words, to have the two
45+
# strings to match you should write this instead:
46+
#
47+
# expr 'A:\Foo' : 'A:\\Foo'
48+
#
49+
# Such behavior makes DOS filenames extremely unpleasant to work with. So
50+
# temporary turn your paths to the Unix notation, and revert them to the
51+
# original notation after the processing. See the macro
52+
# AX_COMPUTE_RELATIVE_PATHS for a concrete example of this.
53+
#
54+
# REFERENCE_STRING defaults to $VARIABLE, this means that slashes will be
55+
# converted to backslashes if $VARIABLE already contains some backslashes
56+
# (see $thirddir below).
57+
#
58+
# firstdir='/usr/local//share'
59+
# seconddir='C:\Program Files\\'
60+
# thirddir='C:\home/usr/'
61+
# AX_NORMALIZE_PATH([firstdir])
62+
# AX_NORMALIZE_PATH([seconddir])
63+
# AX_NORMALIZE_PATH([thirddir])
64+
# # $firstdir = '/usr/local/share'
65+
# # $seconddir = 'C:\Program Files'
66+
# # $thirddir = 'C:\home\usr'
67+
#
68+
# LICENSE
69+
#
70+
# Copyright (c) 2008 Alexandre Duret-Lutz <adl@gnu.org>
71+
#
72+
# This program is free software; you can redistribute it and/or modify it
73+
# under the terms of the GNU General Public License as published by the
74+
# Free Software Foundation; either version 2 of the License, or (at your
75+
# option) any later version.
76+
#
77+
# This program is distributed in the hope that it will be useful, but
78+
# WITHOUT ANY WARRANTY; without even the implied warranty of
79+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
80+
# Public License for more details.
81+
#
82+
# You should have received a copy of the GNU General Public License along
83+
# with this program. If not, see <http://www.gnu.org/licenses/>.
84+
#
85+
# As a special exception, the respective Autoconf Macro's copyright owner
86+
# gives unlimited permission to copy, distribute and modify the configure
87+
# scripts that are the output of Autoconf when processing the Macro. You
88+
# need not follow the terms of the GNU General Public License when using
89+
# or distributing such scripts, even though portions of the text of the
90+
# Macro appear in them. The GNU General Public License (GPL) does govern
91+
# all other use of the material that constitutes the Autoconf Macro.
92+
#
93+
# This special exception to the GPL applies to versions of the Autoconf
94+
# Macro released by the Autoconf Archive. When you make and distribute a
95+
# modified version of the Autoconf Macro, you may extend this special
96+
# exception to the GPL to apply to your modified version as well.
97+
98+
#serial 5
99+
100+
AU_ALIAS([ADL_NORMALIZE_PATH], [AX_NORMALIZE_PATH])
101+
AC_DEFUN([AX_NORMALIZE_PATH],
102+
[case ":[$]$1:" in
103+
# change empty paths to '.'
104+
::) $1='.' ;;
105+
# strip trailing slashes
106+
:*[[\\/]]:) $1=`echo "[$]$1" | sed 's,[[\\/]]*[$],,'` ;;
107+
:*:) ;;
108+
esac
109+
# squeze repeated slashes
110+
case ifelse($2,,"[$]$1",$2) in
111+
# if the path contains any backslashes, turn slashes into backslashes
112+
*\\*) $1=`echo "[$]$1" | sed 's,\(.\)[[\\/]][[\\/]]*,\1\\\\,g'` ;;
113+
# if the path contains slashes, also turn backslashes into slashes
114+
*) $1=`echo "[$]$1" | sed 's,\(.\)[[\\/]][[\\/]]*,\1/,g'` ;;
115+
esac])

0 commit comments

Comments
 (0)