From: Yao Zi Date: Mon, 9 Sep 2024 18:08:30 +0000 (+0000) Subject: bash-completion: look: rewrite completion logic X-Git-Tag: v2.42-start~208^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5aee3a1e6b0609acca371307f418f89e5a641136;p=thirdparty%2Futil-linux.git bash-completion: look: rewrite completion logic look(1) opens /usr/share/dict/words as dictionary by default. Doing TAB completion for look(1) without the dictionary installed will result in popups like $ look look: /usr/share/dict/words: No such file or directory messing up the terminal. As /usr/share/dict/words is not shipped by quite a few distros nowadays and it should not be listed as a hard dependency of util-linux, we make sure the dictionary exists before calling look(1) when doing completion, avoiding these error messages. When completing the word without anything specified on the command line, alphabets and numbers instead of all words are listed as a hint, for better interacting experience. Signed-off-by: Yao Zi --- diff --git a/bash-completion/look b/bash-completion/look index feafe2379..8bae52c61 100644 --- a/bash-completion/look +++ b/bash-completion/look @@ -22,7 +22,17 @@ _look_module() esac case $COMP_CWORD in 1) - COMPREPLY=( $(compgen -W "$(look "$cur")" -- $cur) ) + [ -f /usr/share/dict/words ] || return 0 + if [ "$cur" ]; then + COMPREPLY=( $(compgen -W "$(look "$cur")" -- $cur) ) + else + COMPREPLY=( $(compgen -W \ + "0 1 2 3 4 5 6 7 8 9 \ + a b c d e f g h i j k l m n o p \ + q r s t u v w x y z \ + A B C D E F G H I J K L M N O P \ + Q R S T U V W X Y Z") ) + fi ;; 2) local IFS=$'\n'