Skip to content

Commit 07bf249

Browse files
authored
Add bash completion script (mtrojnar#125)
1 parent 357747d commit 07bf249

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

Makefile.am

+5
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ bin_PROGRAMS = osslsigncode
1414

1515
osslsigncode_SOURCES = osslsigncode.c msi.c msi.h
1616
osslsigncode_LDADD = $(OPENSSL_LIBS) $(OPTIONAL_LIBCURL_LIBS)
17+
18+
# bash completion script
19+
AM_DISTCHECK_CONFIGURE_FLAGS = --with-bashcompdir='$$(datarootdir)/bash-completion/completions'
20+
bashcompdir = @bashcompdir@
21+
dist_bashcomp_DATA = osslsigncode.bash

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# osslsigncode change log
2+
- added bash completion script
3+
- added CA bundle auto-detection
4+
15
### 2.2 (2021.08.15)
26

37
- CAT files support (thanks to James McKenzie)

configure.ac

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ AM_INIT_AUTOMAKE
77

88
AC_CONFIG_SRCDIR([osslsigncode.c])
99

10+
# bash completion support
11+
AC_ARG_WITH([bashcompdir],
12+
AS_HELP_STRING([--with-bashcompdir=DIR], [directory for bash completions]), ,
13+
[PKG_CHECK_VAR([with_bashcompdir], [bash-completion], [completionsdir], ,
14+
[with_bashcompdir="${datarootdir}/bash-completion/completions"])])
15+
AC_MSG_CHECKING([for bashcompdir])
16+
AC_MSG_RESULT([$with_bashcompdir])
17+
AC_SUBST([bashcompdir], [$with_bashcompdir])
18+
1019
dnl Checks for programs.
1120
AC_PROG_CC
1221
AC_USE_SYSTEM_EXTENSIONS

osslsigncode.bash

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# bash completion for osslsigncode -*- shell-script -*-
2+
# Copyright (C) 2021-2022 Michał Trojnara <Michal.Trojnara@stunnel.org>
3+
# Author: Małgorzata Olszówka <Malgorzata.Olszowka@stunnel.org>
4+
5+
bind 'set show-all-if-ambiguous on'
6+
bind 'set completion-ignore-case on'
7+
COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
8+
9+
_comp_cmd_osslsigncode()
10+
{
11+
local cur prev words cword
12+
_init_completion || return
13+
14+
local commands command options timestamps rfc3161
15+
16+
commands="--help --version -v
17+
sign add attach-signature extract-signature remove-signature verify"
18+
19+
timestamps="http://timestamp.digicert.com
20+
http://time.certum.pl
21+
http://timestamp.sectigo.com
22+
http://timestamp.globalsign.com/?signature=sha2"
23+
24+
rfc3161="http://timestamp.digicert.com
25+
http://time.certum.pl
26+
http://timestamp.entrust.net/TSS/RFC3161sha2TS
27+
http://tss.accv.es:8318/tsa
28+
http://kstamp.keynectis.com/KSign/
29+
http://sha256timestamp.ws.symantec.com/sha256/timestamp"
30+
31+
32+
if ((cword == 1)); then
33+
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
34+
else
35+
command=${words[1]}
36+
case $prev in
37+
-ac | -c | -catalog | -certs | -spc | -key | -pkcs12 | -pass | \
38+
-readpass | -pkcs11engine | -pkcs11module | -in | -out | -sigin | \
39+
-n | -CAfile | -CRLfile | -TSA-CAfile | -TSA-CRLfile)
40+
_filedir
41+
return
42+
;;
43+
-h | -require-leaf-hash)
44+
COMPREPLY=($(compgen -W 'md5 sha1 sha2 sha256 sha384 sha512' \
45+
-- "$cur"))
46+
return
47+
;;
48+
-jp)
49+
COMPREPLY=($(compgen -W 'low medium high' -- "$cur"))
50+
return
51+
;;
52+
-t)
53+
COMPREPLY=($(compgen -W "${timestamps}" -- "$cur"))
54+
return
55+
;;
56+
-ts)
57+
COMPREPLY=($(compgen -W "${rfc3161}" -- "$cur"))
58+
return
59+
;;
60+
-i | -p)
61+
_known_hosts_real -- "$cur"
62+
return
63+
;;
64+
esac
65+
66+
if [[ $cur == -* ]]; then
67+
# possible options for the command
68+
options=$(_parse_help "$1" "$command --help" 2>/dev/null)
69+
COMPREPLY=($(compgen -W "${options}" -- ${cur}))
70+
fi
71+
fi
72+
73+
} &&
74+
complete -F _comp_cmd_osslsigncode osslsigncode
75+
76+
# ex: filetype=sh

0 commit comments

Comments
 (0)