diff --git a/gh-find-code b/gh-find-code index a6a7f63..63a6b4c 100755 --- a/gh-find-code +++ b/gh-find-code @@ -294,7 +294,7 @@ validate_environment() { # Check if the necessary history file exists and is readable and writable if ((GHFC_HISTORY_LIMIT)); then if [[ -d $GHFC_HISTORY_FILE ]]; then - die "$GHFC_HISTORY_FILE is a directory" + die "'$GHFC_HISTORY_FILE' is a directory. Please specify a file path for the GHFC_HISTORY_FILE." fi if [[ ! -f $GHFC_HISTORY_FILE ]]; then @@ -683,7 +683,9 @@ gh_query() { grep_args+=("--regexp=$pattern") done - # Run the grep command directly with the expanded array + # Use the '--text' flag, as grep will simply print 'Binary file … matches' if + # the file contains binary characters. It won't even throw an error. + # https://unix.stackexchange.com/questions/19907 command grep --color=never --line-number --text --fixed-strings "${grep_args[@]}" -- \ "${store_file_contents}_${index}_fetched" 2>"${redirect_location}" | command cut -d: -f1 >>"${store_file_contents}_${index}_line_numbers" @@ -782,13 +784,15 @@ view_contents() { bat_args+=("--language=${file_extension}") fi line_numbers=() - while IFS= read -r matched_line; do - line_numbers+=("$matched_line") - # NOTE: The '--line-range' in 'bat' overrides preceding flags. However, the - # '-H, --highlight-line' attribute can be utilized multiple times. - # https://github.com/sharkdp/bat/pull/162#pullrequestreview-125072252 - # use the short form to avoid making the command unnecessarily long - bat_args+=("-H=${matched_line}") + while IFS=$'\n' read -r matched_line; do + if [[ $matched_line =~ ^[0-9]+ ]]; then + line_numbers+=("$matched_line") + # NOTE: The '--line-range' in 'bat' overrides preceding flags. However, the + # '-H, --highlight-line' attribute can be utilized multiple times. + # https://github.com/sharkdp/bat/pull/162#pullrequestreview-125072252 + # use the short form to avoid making the command unnecessarily long + bat_args+=("-H=${matched_line}") + fi done <"${store_file_contents}_${index}_line_numbers" file_name=$(command basename "$file_path")