Generated bash completion at configure time

This commit is contained in:
Jakub Wilk 2016-05-26 14:55:24 +02:00
parent f62ff771b8
commit 0f02e6e551
3 changed files with 29 additions and 52 deletions

View file

@ -29,7 +29,16 @@ AM_CONDITIONAL([ENABLE_BASH_COMPLETION],[test "x$with_bash_completion_dir" != "x
# TIO_CHECK_BAUDRATE(N)
AC_DEFUN(
[TIO_CHECK_BAUDRATE],
[AC_CHECK_DECLS([B$1], [AC_SUBST([B$1], [$1])], [], [[#include <termios.h>]])]
[
tio_have_decl=0
AS_IF([test $1 -le 38400],
# Baud rates up to 38400 are defined by POSIX,
# so we don't have to check for them.
[tio_have_decl=1],
[AC_CHECK_DECLS([B$1], [tio_have_decl=1], [], [[#include <termios.h>]])]
)
AS_IF([test $tio_have_decl = 1], [AC_SUBST([BAUDRATES], ["$BAUDRATES $1"])])
]
)
# TIO_CHECK_BAUDRATES(N1, N2, ...)
@ -39,7 +48,24 @@ AC_DEFUN(
)
# Check for available terminal I/O speeds
BAUDRATES=
TIO_CHECK_BAUDRATES(
0,
50,
75,
110,
134,
150,
200,
300,
600,
1200,
1800,
2400,
4800,
9600,
19200,
38400,
57600,
115200,
230400,
@ -59,5 +85,6 @@ TIO_CHECK_BAUDRATES(
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([src/Makefile])
AC_CONFIG_FILES([src/bash-completion/tio])
AC_CONFIG_FILES([man/Makefile])
AC_OUTPUT

View file

@ -14,26 +14,6 @@ tio_SOURCES = tty.c \
include/tio/error.h
if ENABLE_BASH_COMPLETION
CLEANFILES = bash-completion/tio
do_subst = sed -e 's/57600 /$(B57600) /g' \
-e 's/115200 /$(B115200) /g' \
-e 's/230400 /$(B230400) /g' \
-e 's/460800 /$(B460800) /g' \
-e 's/500000 /$(B500000) /g' \
-e 's/576000 /$(B576000) /g' \
-e 's/921600 /$(B921600) /g' \
-e 's/1000000 /$(B1000000) /g' \
-e 's/1152000 /$(B1152000) /g' \
-e 's/1500000 /$(B1500000) /g' \
-e 's/2000000 /$(B2000000) /g' \
-e 's/2500000 /$(B2500000) /g' \
-e 's/3000000 /$(B3000000) /g' \
-e 's/3500000 /$(B3500000) /g' \
-e 's/4000000/$(B4000000)/g'
bash-completion/tio: bash-completion/tio.in
$(do_subst) < bash-completion/tio.in > bash-completion/tio
bashcompletiondir=@BASH_COMPLETION_DIR@
dist_bashcompletion_DATA=bash-completion/tio

View file

@ -24,37 +24,7 @@ _tio()
# Complete the arguments to the options.
case "${prev}" in
-b | --baudrate)
local baudrates="0 \
50 \
75 \
110 \
134 \
150 \
200 \
300 \
600 \
1200 \
1800 \
2400 \
4800 \
9600 \
19200 \
38400 \
57600 \
115200 \
230400 \
460800 \
500000 \
576000 \
921600 \
1000000 \
1152000 \
1500000 \
2000000 \
2500000 \
3000000 \
3500000 \
4000000"
local baudrates="@BAUDRATES@"
COMPREPLY=( $(compgen -W "$baudrates" -- ${cur}) )
return 0
;;