Skip to content

Commit

Permalink
fix(gcc): explicitly check existence of the commands
Browse files Browse the repository at this point in the history
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.
scop#390
akinomyoga/ble.sh#192
akinomyoga/ble.sh#203
  • Loading branch information
akinomyoga committed Jul 8, 2022
1 parent 730368b commit 109be77
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions completions/gcc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 109be77

Please sign in to comment.