From 6aff97100f6d8d296090a796e4298f8b500d59bf Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Thu, 13 Aug 2020 11:30:06 +0200 Subject: [PATCH] Add bash completion of tty devices. --- src/bash-completion/tio.in | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/bash-completion/tio.in b/src/bash-completion/tio.in index a0d062d..6da7b0d 100644 --- a/src/bash-completion/tio.in +++ b/src/bash-completion/tio.in @@ -4,7 +4,7 @@ _tio() { - local cur prev opts base + local cur prev opts base ttys COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" @@ -76,9 +76,20 @@ _tio() *) ;; esac + case "${cur}" in + -*) + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + return 0 + ;; + esac - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) - return 0 + if [ -d /dev/serial/by-id ]; then + ttys=$(printf '%s\n' /dev/tty* /dev/serial/by-id/*) + else + ttys=$(printf '%s\n' /dev/tty*) + fi + COMPREPLY=( $(compgen -W "${ttys}" -- ${cur}) ) + return 0 } # Bind completion to tio command