From df8652f05d36fb8e2ea91b74f962e192164ec9a8 Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Sat, 27 Sep 2014 18:26:12 +0200 Subject: [PATCH] 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 . --- src/Makefile.am | 2 +- .../gotty} | 47 ++++++++++--------- 2 files changed, 25 insertions(+), 24 deletions(-) rename src/{gotty-bash-completion.sh => bash-completion/gotty} (78%) diff --git a/src/Makefile.am b/src/Makefile.am index 0807e31..71da405 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/gotty-bash-completion.sh b/src/bash-completion/gotty similarity index 78% rename from src/gotty-bash-completion.sh rename to src/bash-completion/gotty index 3f24633..63a0fcd 100644 --- a/src/gotty-bash-completion.sh +++ b/src/bash-completion/gotty @@ -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 ;; @@ -87,7 +86,9 @@ _gotty() ;; esac - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) return 0 } + +# Bind completion to gotty command complete -o default -F _gotty gotty