Skip to content

Commit c842946

Browse files
committed
fix(gcc): explicitly check existence of the commands
When either 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. akinomyoga/ble.sh#203 akinomyoga/ble.sh#192 #390
1 parent 730368b commit c842946

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

completions/gcc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,25 @@ _gcc()
5858
complete -F _gcc gcc{,-5,-6,-7,-8} g++{,-5,-6,-7,-8} g77 g95 \
5959
gccgo{,-5,-6,-7,-8} gcj gfortran{,-5,-6,-7,-8} gpc &&
6060
{
61-
if cc --version 2>/dev/null | command grep -q GCC ||
61+
if type cc &>/dev/null && cc --version 2>/dev/null | command grep -q GCC ||
6262
[[ $(_realcommand cc) == *gcc* ]]; then
6363
complete -F _gcc cc
6464
else
6565
complete -F _minimal cc
6666
fi
67-
if c++ --version 2>/dev/null | command grep -q GCC ||
67+
if type c++ &>/dev/null && c++ --version 2>/dev/null | command grep -q GCC ||
6868
[[ $(_realcommand c++) == *g++* ]]; then
6969
complete -F _gcc c++
7070
else
7171
complete -F _minimal c++
7272
fi
73-
if f77 --version 2>/dev/null | command grep -q GCC ||
73+
if type f77 &>/dev/null && f77 --version 2>/dev/null | command grep -q GCC ||
7474
[[ $(_realcommand f77) == *gfortran* ]]; then
7575
complete -F _gcc f77
7676
else
7777
complete -F _minimal f77
7878
fi
79-
if f95 --version 2>/dev/null | command grep -q GCC ||
79+
if type f95 &>/dev/null && f95 --version 2>/dev/null | command grep -q GCC ||
8080
[[ $(_realcommand f95) == *gfortran* ]]; then
8181
complete -F _gcc f95
8282
else

0 commit comments

Comments
 (0)