From 8920f87b67c5c8e34768dc75e637e0b2f29586ba Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Fri, 8 Jul 2022 10:54:44 +0900 Subject: [PATCH 1/3] fix(gcc): explicitly check existence of the commands When at least one of the commands "cc", "c++", "f77", and "f95" is not found in the system, on the first load of "gcc" completions, "command_not_found_handle" hook (typically set by distributions) is invoked in the middle of completion, breaks the terminal layout by outputting messages, and eats user inputs. This commit fixes the issue by checking the existence of commands before running these commands. Refs. https://github.com/scop/bash-completion/pull/390 https://github.com/akinomyoga/ble.sh/issues/192 https://github.com/akinomyoga/ble.sh/issues/203 --- completions/gcc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/completions/gcc b/completions/gcc index 41913b01164..6fabfeea529 100644 --- a/completions/gcc +++ b/completions/gcc @@ -58,25 +58,25 @@ _gcc() complete -F _gcc gcc{,-5,-6,-7,-8} g++{,-5,-6,-7,-8} g77 g95 \ gccgo{,-5,-6,-7,-8} gcj gfortran{,-5,-6,-7,-8} gpc && { - if cc --version 2>/dev/null | command grep -q GCC || + if type cc &>/dev/null && cc --version 2>/dev/null | command grep -q GCC || [[ $(_realcommand cc) == *gcc* ]]; then complete -F _gcc cc else complete -F _minimal cc fi - if c++ --version 2>/dev/null | command grep -q GCC || + if type c++ &>/dev/null && c++ --version 2>/dev/null | command grep -q GCC || [[ $(_realcommand c++) == *g++* ]]; then complete -F _gcc c++ else complete -F _minimal c++ fi - if f77 --version 2>/dev/null | command grep -q GCC || + if type f77 &>/dev/null && f77 --version 2>/dev/null | command grep -q GCC || [[ $(_realcommand f77) == *gfortran* ]]; then complete -F _gcc f77 else complete -F _minimal f77 fi - if f95 --version 2>/dev/null | command grep -q GCC || + if type f95 &>/dev/null && f95 --version 2>/dev/null | command grep -q GCC || [[ $(_realcommand f95) == *gfortran* ]]; then complete -F _gcc f95 else From 3e4ec088033ac2794f355e3df07d6928d05540dc Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Fri, 8 Jul 2022 11:11:30 +0900 Subject: [PATCH 2/3] fix(_bashcomp_try_faketty): explicitly check existence of the command --- bash_completion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_completion b/bash_completion index 8ab042a019b..6bcfcca9fb1 100644 --- a/bash_completion +++ b/bash_completion @@ -1822,7 +1822,7 @@ _bashcomp_try_faketty() { if type unbuffer &>/dev/null; then unbuffer -p "$@" - elif script --version 2>&1 | command grep -qF util-linux; then + elif type script &>/dev/null && script --version 2>&1 | command grep -qF util-linux; then # BSD and Solaris "script" do not seem to have required features script -qaefc "$*" /dev/null else From 96ac410b2784d2bdb125d33b4b8435800c2d53ce Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 10 Jul 2022 21:20:38 +0900 Subject: [PATCH 3/3] fix(_parse_{help,usage}): avoid command_not_found_handle --- bash_completion | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bash_completion b/bash_completion index 6bcfcca9fb1..3e19284d4fc 100644 --- a/bash_completion +++ b/bash_completion @@ -1112,7 +1112,7 @@ _parse_help() ( case $cmd in -) exec cat ;; - *) _comp_dequote "$cmd" && LC_ALL=C "$ret" ${2:---help} 2>&1 ;; + *) _comp_dequote "$cmd" && type -- "$ret" &>/dev/null && LC_ALL=C "$ret" ${2:---help} 2>&1 ;; esac ) | while read -r line; do @@ -1149,7 +1149,7 @@ _parse_usage() ( case $cmd in -) exec cat ;; - *) _comp_dequote "$cmd" && LC_ALL=C "$ret" ${2:---usage} 2>&1 ;; + *) _comp_dequote "$cmd" && type -- "$ret" &>/dev/null && LC_ALL=C "$ret" ${2:---usage} 2>&1 ;; esac ) | while read -r line; do