Completed autocompletion

Autocompletion now resolves all arguments.

Also renamed 'gotty-bash-completion.sh' to 'gotty' to comply with the
normal naming scheme for completion files in /etc/bash_completion.d .
This commit is contained in:
Martin Lund 2014-09-27 18:26:12 +02:00
parent cfa4430370
commit df8652f05d
2 changed files with 25 additions and 24 deletions

View file

@ -1,4 +1,4 @@
bin_PROGRAMS = gotty
gotty_SOURCES = tty.c options.c device.c main.c
bashcompletiondir=$(sysconfdir)/bash_completion.d
dist_bashcompletion_DATA=gotty-bash-completion.sh
dist_bashcompletion_DATA=bash-completion/gotty

View file

@ -1,3 +1,7 @@
#
# Bash autocompletion script for gotty.
#
_gotty()
{
local cur prev opts base
@ -5,24 +9,19 @@ _gotty()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
#
# The options we'll complete.
#
opts="--baudrate \
--databits \
--flow \
--stopbits \
--parity \
--no-autoconnect \
--version \
--help"
opts="-b --baudrate \
-d --databits \
-f --flow \
-s --stopbits \
-p --parity \
-n --no-autoconnect \
-v --version \
-h --help"
#
# Complete the arguments to some of the options.
#
# Complete the arguments to the options.
case "${prev}" in
--baudrate)
-b | --baudrate)
local baudrates="0 \
50 \
75 \
@ -55,31 +54,31 @@ _gotty()
COMPREPLY=( $(compgen -W "$baudrates" -- ${cur}) )
return 0
;;
--databits)
-d | --databits)
COMPREPLY=( $(compgen -W "5 6 7 8" -- ${cur}) )
return 0
;;
--flow)
-f | --flow)
COMPREPLY=( $(compgen -W "hard soft none" -- ${cur}) )
return 0
;;
--stopbits)
-s | --stopbits)
COMPREPLY=( $(compgen -W "1 2" -- ${cur}) )
return 0
;;
--parity)
-p | --parity)
COMPREPLY=( $(compgen -W "even odd none" -- ${cur}) )
return 0
;;
--no-autoconnect)
-n | --no-autoconnect)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
--version)
-v | --version)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
--help)
-h | --help)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
@ -90,4 +89,6 @@ _gotty()
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
}
# Bind completion to gotty command
complete -o default -F _gotty gotty